@@ -105,27 +105,27 @@ namespace partdiff {
105105 return result;
106106 };
107107
108- auto number = &( this ->options .number ) ;
108+ auto & number = this ->options .number ;
109109 this ->add_argument (" num" , number, std::format (" number of threads ({:d})" , num_bounds), num_bounds);
110110
111- auto method = &( this ->options .method ) ;
111+ auto & method = this ->options .method ;
112112 this ->add_argument (" method" , method,
113113 std::format (" calculation method ({:d})\n {}" , method_bounds, display_enum (method_bounds)),
114114 method_bounds);
115115
116- auto interlines = &( this ->options .interlines ) ;
116+ auto & interlines = this ->options .interlines ;
117117 this ->add_argument (" lines" , interlines,
118118 std::format (" number of interlines ({1:d})\n "
119119 " {0}matrixsize = (interlines * 8) + 9" ,
120120 indent, lines_bounds),
121121 lines_bounds);
122122
123- auto pert_func = &( this ->options .pert_func ) ;
123+ auto & pert_func = this ->options .pert_func ;
124124 this ->add_argument (" func" , pert_func,
125125 std::format (" perturbation function ({:d})\n {}" , func_bounds, display_enum (func_bounds)),
126126 func_bounds);
127127
128- auto termination = &( this ->options .termination ) ;
128+ auto & termination = this ->options .termination ;
129129 this ->add_argument (" term" , termination,
130130 std::format (" termination condition ({:d})\n {}" , term_bounds, display_enum (term_bounds)),
131131 term_bounds);
@@ -135,10 +135,10 @@ namespace partdiff {
135135 " {0}iterations: {2:d}\n " ,
136136 indent, accuracy_bounds, iteration_bounds));
137137
138- auto term_accuracy = &( this ->options .term_accuracy ) ;
138+ auto & term_accuracy = this ->options .term_accuracy ;
139139 this ->add_argument (" acc" , term_accuracy, std::nullopt , accuracy_bounds);
140140
141- auto term_iteration = &( this ->options .term_iteration ) ;
141+ auto & term_iteration = this ->options .term_iteration ;
142142 this ->add_argument (" iter" , term_iteration, std::nullopt , iteration_bounds);
143143 }
144144
@@ -150,23 +150,23 @@ namespace partdiff {
150150 }
151151
152152 template <class T >
153- void argument_parser::add_argument (std::string name, T * target, std::optional<std::string> description,
153+ void argument_parser::add_argument (std::string name, T & target, std::optional<std::string> description,
154154 bounds_t <T> bounds) {
155155 argument_description arg_desc;
156156 arg_desc.name = name;
157- arg_desc.target = target;
158- arg_desc.read_from_string = [target = arg_desc.target , bounds](const std::string &input) {
159- T *casted_ptr = std::any_cast<T *>(target );
157+ arg_desc.target = std::reference_wrapper<T>( target) ;
158+ arg_desc.read_from_string = [target_ref_any = arg_desc.target , bounds](const std::string &input) {
159+ auto &target_ref = std::any_cast<std::reference_wrapper<T>>(target_ref_any). get ( );
160160 bool valid_input = false ;
161161 std::istringstream iss (input);
162162 if constexpr (std::is_enum_v<T>) {
163163 std::underlying_type_t <T> temp;
164164 valid_input = static_cast <bool >(iss >> temp);
165- *casted_ptr = static_cast <T>(temp);
165+ target_ref = static_cast <T>(temp);
166166 } else {
167- valid_input = static_cast <bool >(iss >> *casted_ptr );
167+ valid_input = static_cast <bool >(iss >> target_ref );
168168 }
169- valid_input &= bounds.contains (*casted_ptr );
169+ valid_input &= bounds.contains (target_ref );
170170 return valid_input;
171171 };
172172 arg_desc.description = description;
0 commit comments