Using minimal type ambiguity in C++ -



Using minimal type ambiguity in C++ -

i have info construction in c++ programme has attributes of type 'vector' (defined me), , of type 'double'. in place in code, much able iterate through info structure, , perform same arithmetic operations on each value. operators need defined vector, code literally looks same need vector type , double type.

if @ possible, avoid iterating through 'vector values' , separately iterating through 'double values'.

i realize straining strict-typing of c++, there way accomplish this?

edit:

right now, i'm doing routine operations this:

e.values.vel = k0[i].vel + k1[i].vel * c_1; e.values.acc = k0[i].acc + k1[i].acc * c_1; ....

(e , k0[i] same class type)

right now, thing keeping me generalizing e's type fact of e's values may vectors, , may doubles, , ideally code deal different objects of type may have different numbers or kinds of values. want like:

for (int j = 0; j < e.values.size(); j ++) { e.values[j] = k0[i].values[j] + k1[i].values[j] }

ideally, have e iterable, or provide sort of next function, that, either: have store it's variables in array can contain 1 known type, or provide next function can homecoming 1 known type.

i'm trying find way can abstract concept can iterate through of e's type without knowing type of each value.

you might want consider boost.fusion. allows turn type compile-time sequence, can utilize compile-time-expanding foreach phone call appropriate functor each element.

c++ types operators abstraction

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -