strong_type
strong_type copied to clipboard
How to compare aliases of simliar types via the similar type
I would like to use a Length as a kind of base type for a Width and a Length type. Following the Tips section I tried:
// have similar Length types
template <typename Tag>
using Length = strong::type<
double, Tag,
strong::regular,
strong::ordered // ,
// strong::implicitly_convertible_to<double> // make it usable where a double is needed.
>;
using Width = Length<struct width_tag>;
using Height = Length<struct height_tag>;
bool higherThanWide(Height h, Width w)
{
// Height and With are Lengths so we should be able to compare them.
if ((Length)h > (Length)w) return true; // (1)
return false;
}
However the comparison (1) does not compile.
If I add strong::implicitly_convertible_to
if (h > w) return true;
works.
I guess, Im looking for a way to use a Height or Width as a Length?