Skip to content

How to compare aliases of simliar types via the similar type #57

@miemoe

Description

@miemoe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions