Edit I completely forgot to mention something obvious to me:
a_func() wants to change var_xxx , so solutions that iterate using the type const do not completely satisfy (although they give ideas, of course).
I feel the answer is simple, but he cannot find it.
Given:
The number (a small number, for example 6, 8, 10) of variables of the user class type (exactly, a mathematical vector object), where each variable must have a unique name determined by the algorithm (in order to be calculated and then used independently, and to be able to easily consult the paper on which the code is based)
make:
In a piece of code, compute and initialize these variables, referencing them by name; and then, in another piece of code, they perform an operation on them in a scan without the need to duplicate the code that causes the operation (i.e., function) for each variable.
The code is as follows:
// in a class declaration vector_type var_abc, var_efg, var_xyz; // in a class member function // "some_math_xxx" pieces are coded inline, not as separate functions var_abc = /* some_math_abc */; var_efg = /* some_math_efg */ ; var_xyz = /* some_math_xyz */ ; a_func(var_abc); a_func(var_efg); a_func(var_xyz);
I mean, I can of course dial a_func(var_xxx) six or more times. But that, well, is simply wrong for me.
Thought of:
- a hash to store the names of these cars (bad for math, using them later, I think)
- a
std::array<> pointers to var (bit awkward but working) this code that is not compiled:
for (vector_type& vr : { var_abc, var_efg, var_xyz }) { a_func(vr); } for (vector_type& vr : { var_abc, var_efg, var_xyz }) { a_func(vr); } (error: binding const vector_type to reference of type vector_type& )
How would you solve this? Of course, I would prefer an elegant solution. The standard is best just C ++ 11, although C ++ 14 is also good if it allows you to get a super-nice solution to this problem.
PS The question entry form says: "the name is subjective and Q may be closed." I am sure that this is not based on the opinions of Q, as I am not asking to compare solutions, but to offer some.