因为
std::disjunction<Args...>
从中的第一个类型继承
Args...
value
true
,或者如果不存在此类类型,则
,我们可以(ab)使用它来生成多路分支:
template<class... Args>
using select = typename std::disjunction<Args...>::type;
template<bool V, class T>
struct when {
static constexpr bool value = V;
using type = T;
};
template<bool is_signed, std::size_t has_sizeof>
using find_int_type = select<
when<is_signed, select<
when<has_sizeof==4, int>,
when<has_sizeof==8, std::int64_t>,
when<false, void>
>>,
when<!is_signed, select<
when<has_sizeof==4, unsigned int>,
when<has_sizeof==8, std::uint64_t>,
when<false, void>
>>
>;