PrevUpHomeNext

Type relationship dominates

The dominates type trait plays a role in modifying the overload set when construction or making an assingment to variant using the T && (forwarding-reference) constructor.

dominates is a predicate which is used to eliminate a type from the overload set in the case that a "stronger match" is present, which overload resolution wouldn't normally eliminate.

dominates is used to implement the "priority" for integral types described in the design.

Valid Expressions

expression

value

A, B, C

any types

strict_variant::dominates<A, B, C>::value

true if A is a strictly better match for C than B is for C.

Synopsis

The default implementation will only returns true in scenarios in which A, B, C are arithmetic types or types which decay to arithmetic, which means they are arithmetic types with CV qualifiers and/or references.

template <typename A, typename B, typename C, typename ENABLE = void>
struct dominates : std::false_type {};

template <typename A, typename B, typename C>
struct dominates<A, B, C,
                 mpl::enable_if_t<decay_to_arithmetic<A>::value && decay_to_arithmetic<B>::value
                                  && decay_to_arithmetic<C>::value
                                  && !safely_constructible<A, B>::value
                                  && safely_constructible<B, A>::value>> : std::true_type {};

Notes

See also variant::variant(T &&) constructor documentation.

[Note] Note

You may specialize dominates as you please in order to modify the overload resolution process further.

However, it may be best to take care that, for any fixed type C, the relation dominates<A, B, C>::value behaves as a partial order (when first two parameters are varied). The reason is that if X, Y, and Z are candidates in some conversion, and X dominates Y, Y dominates Z, and Z dominates X, then all types will be removed. The fact Y was eliminated because of being dominated by X doesn't prevent Z from being eliminated for instance. If dominates is induced by a partial order, then such "cycles" cannot occur and dominates will never result in all candidates being eliminated. The default definition has this property.


PrevUpHomeNext