I have a template class which has a lot of variables, all of the same type
template<typename T>
struct Location
{
T lat;
T lon;
T alt;
// and roughly 20 variables more of type T
};
In my code T
is either float
or double
, depending on the precision I need. Sometimes I need to cast between these two struct. Thus I want to define a conversion operator
template<typename A, typename B> operator Location<B> {
Location<B> ret;
// cast every variable in *this from type A to type B
return ret;
}
Since there are a lot of variables in Location
and it is very likely that I will need to add more variables to the struct in future, I do not want to write each cast by hand in my conversion operator.
Thus, I want to know whether there is some automagically way to cast all variables in the struct?