How can we implement a variational pattern that defines the type T and the list of types E 1 , E 2 , ... E N , determines the type of list for which the conversion from T to this type, in accordance with the resolution of the overload, is the best?
void should be the result if the best conversion does not exist - in other words, when either there is ambiguity, or T cannot be converted to any type in the list.
Please note that this means that our template must be SFINAE-friendly, i.e. It is not a blunder when the best conversion does not exist.
The following static_assert should succeed:
static_assert( std::is_same< best<int, long, short>, void >{}, "" ); static_assert( std::is_same< best<int, long, std::string>, long >{}, "" ); static_assert( std::is_same< best<int>, void >{}, "" );
(Assuming for simplicity that best is an alias pattern related to the actual pattern)
This case is not defined:
static_assert( std::is_same< best<int, int, int>, ???>{}, "" );
Either void or int should be acceptable here. (If the latter is selected, we can still check the shell template to see if the result type will be contained twice in the list, and if it is, print void ).