Created on 2020-06-30.00:00:00 last changed 54 months ago
[ 2020-07-12; Reflector prioritization ]
Set priority to 3 after reflector discussions.
[concept.convertible] p2:
Types From and To model convertible_to<From, To> only if:
(2.1) — To is not an object or reference-to-object type, or static_cast<To>(f()) is equal to test(f).
[…]
This requires the implicit and explicit conversions to produce equal results.
However, it seems that when To is a reference-to-function type, this restriction does not apply. This makes it possible to create a class that models convertible_to, but produces different results depending on the kind of conversion:#include <concepts> int foo() { return 0; } int bar() { return 42; } using FT = int(); struct A { operator FT&() const { return foo; } explicit operator FT&() { return bar; } }; static_assert(std::convertible_to<A, FT&>); A a; FT& x = a; // x == foo auto y = static_cast<FT&>(a); // y == bar
History | |||
---|---|---|---|
Date | User | Action | Args |
2020-07-12 16:33:28 | admin | set | messages: + msg11362 |
2020-06-30 00:00:00 | admin | create |