Tencent/flare

About unboxed_type_t

4kangjc opened this issue · 2 comments

template <class... Ts>
using unboxed_type_t = typename std::conditional_t<
sizeof...(Ts) == 0, std::common_type<void>,
std::conditional_t<sizeof...(Ts) == 1, std::common_type<Ts...>,
std::common_type<std::tuple<Ts...>>>>::type;

这个会不会更好点,更易于理解? common_type有点难懂

template <class T0 = void, class... Ts>
struct unboxed_type {
  using type = std::conditional_t<sizeof...(Ts) == 0, T0, std::tuple<T0, Ts...>>;
};

template <class... Ts>
using unboxed_type_t = typename unboxed_type<Ts...>::type;

两种写法其实倒无所谓写哪个,毕竟写模板的应该都对各种晦涩语法习惯了

不过确实应该有一个struct unboxed_type,这儿直接using成了一连串东西可能是一开始写在了某个类内部后来挪出来了。写在类内部的时候我有时候喜欢直接using xxx_t = 一连串东西,主要是图个省事

两种写法其实倒无所谓写哪个,毕竟写模板的应该都对各种晦涩语法习惯了

不过确实应该有一个struct unboxed_type,这儿直接using成了一连串东西可能是一开始写在了某个类内部后来挪出来了。写在类内部的时候我有时候喜欢直接using xxx_t = 一连串东西,主要是图个省事

好的