Боюсь, вам нужно накатить свое.Вы можете деформировать свои типы в std :: tuple, а затем передать его в std::common_type
, например,
#include <tuple>
#include <type_traits>
template <class T1, class T2>
struct common {
using type = typename std::tuple_element<0, typename std::common_type<std::tuple<T1>, std::tuple<T2>>::type>::type;
};
template <class T>
struct common<const T, T> {
using type = const T;
};
template <class T>
struct common<T, const T> {
using type = const T;
};
template <class T>
struct common<const T, const T> {
using type = const T;
};
int main()
{
static_assert(std::is_same<common<int, int>::type, int>::value, "");
static_assert(std::is_same<common<const int, int>::type, const int>::value, "");
static_assert(std::is_same<common<int, int &>::type, int>::value, "");
static_assert(std::is_same<common<int &, int &>::type, int &>::value, "");
static_assert(std::is_same<common<int &, int const &>::type, int const &>::value, "");
return 0;
}
Но вы должны создать специальные случаи для const
.