multilineargeometry with coordinate type that uses expression templates
When using a coordinate type ct
in the class MultiLinearGeometry<ct, dim, dow>
that is implemented with the help of expression templates, e.g. using a multiprecision type boost::multiprecision::number<cpp_dec_float<N> >
, an internal operation fails to compile: multilineargeometry.hh:721
error: operands to ?: have different types
template <class ct, ...>
template <bool add, ...>
void MultiLinearGeometry<ct,...>::global(...) {
// ...
y[ i ] = (add ? y[ i ] + rf*origin[ i ] : rf*origin[ i ]); // line 721
}
The problem is, that in the triple operator ?:
both value expression are complex types coming from the expressions-template context and are different and not convertible into each other. Thus, the operator can not decide what's the correct common type.
Two solutions for this problem can be implemented:
- Add an explicit cast to type
ct
inside of?:
:
y[ i ] = (add ? ct(y[ i ] + rf*origin[ i ]) : ct(rf*origin[ i ]));
- Implement an assigner that is specialized for the template parameter
add
:
template <bool add>
struct Assigner {};
template <>
struct Assigner<true> {
template <class T1, class T2>
void apply(T1& out, T2 const& in) { out += in; }
};
template <>
struct Assigner<false> {
template <class T1, class T2>
void apply(T1& out, T2 const& in) { out = in; }
};
// ...
// multilineargeometry.hh:721
Assigner<add>::apply(y[ i ], rf*origin[ i ]);
I would prefer the second solution. It is more flexible and maybe also more efficient.
I have not yet tested all geometries. Maybe there is another such error in one of the other files.