I am specializing std::common_type
for my type. I defined the following specialization:
common_type<my_type, my_type>
And all is well. Then someone comes along and calls std::common_type<my_type, my_type &>
. The default version acts the same if you pass a reference vs. not a reference (as it calls std::decay
on the types). However, it doesn't defer to the non-reference version of std::common_type
, which I would need to work correctly. Is there a better way than having to do something like this (leaving out rvalue-reference to const for simplicity):
common_type<my_type, my_type>
common_type<my_type, my_type &>
common_type<my_type, my_type const &>
common_type<my_type, my_type volatile &>
common_type<my_type, my_type const volatile &>
common_type<my_type, my_type &&>
common_type<my_type, my_type volatile &&>
common_type<my_type &, my_type>
common_type<my_type const &, my_type>
common_type<my_type volatile &, my_type>
common_type<my_type const volatile &, my_type>
common_type<my_type &&, my_type>
common_type<my_type volatile &&, my_type>
common_type<my_type &, my_type &>
common_type<my_type &, my_type const &>
common_type<my_type &, my_type volatile &>
...
Surely there is a better way? By my count, that is 49 possible versions if we ignore const &&
and const volatile &&
Note: my_type is actually a class template itself, so the specialize actually looks more like
template<intmax_t lhs_min, intmax_t lhs_max, intmax_t rhs_min, intmax_t rhs_max>
class common_type<my_type<lhs_min, lhs_max>, my_type<rhs_min, rhs_max>>
Where the result is my_type<min(lhs_min, rhs_min), max(lhs_max, rhs_max)>
The solution would be fairly straightforward if I had full control over the primary template definitions, but I obviously cannot change std::common_type
.