should std::common_type use std::decay?
Solution 1:
should std::common_type use std::decay?
Yes, see Library Working Group Defect #2141.
Short version (long version, see link above):
declval<A>()
returns aA&&
-
common_type
is specified viadeclval
, n3337:template <class T, class U> struct common_type<T, U> { typedef decltype(true ? declval<T>() : declval<U>()) type; };
common_type<int, int>::type
therefore yieldsint&&
, which is unexpected-
proposed resolution is to add
decay
template <class T, class U> struct common_type<T, U> { typedef decay_t < decltype(true ? declval<T>() : declval<U>()) > type; };
common_type<int, int>::type
now yieldsint