这是一个最小的示例:
const weight = 350;
const time = 7;
const age = 77;
const gender = "male";
if (weight > 300 && time < 6 && age > 17 && gender === "male") {
console.log("Come to our tryout!");
}
else {
console.log ("Come to our cookout!");
}
如果所有template<typename ...Types>
struct Pack {};
template<typename ...TemplateTemplateTypes>
bool AllConstructible()
{
return (std::is_constructible_v
</*do something to archive all types in every TemplateTemplateType*/>
and ... and true);
}
struct Empty{};
int main()
{
std::cout << std::boolalpha << AllConstructible<Pack<int, const int&>, Pack<Empty>>();
}
都为true,则函数AllConstructible
将返回true。
很容易在is_constructible_v<Pack's Types>
的定义内实现所有类型(只需使用Pack
),但是如何在外部实现呢?
答案 0 :(得分:2)
您可以侵入一个无法解压缩参数的助手模板:
template<typename ...Types>
struct Helper;
template<typename ...Types>
struct Helper<Pack<Types...>>
{
static constexpr bool value{std::is_constructible_v<Types...>};
};
template<typename ...TemplateTemplateTypes>
bool AllConstructible()
{
return (Helper<TemplateTemplateTypes>::value and ... and true);
}