strong_type icon indicating copy to clipboard operation
strong_type copied to clipboard

How to compare aliases of simliar types via the similar type

Open miemoe opened this issue 7 months ago • 0 comments

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 then

if (h > w) return true; 

works.

I guess, Im looking for a way to use a Height or Width as a Length?

miemoe avatar May 30 '25 08:05 miemoe