下面是一个最小的例子:
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>>();
}如果所有is_constructible_v<Pack's Types>都为true,则函数AllConstructible将返回true。
在Pack定义内实现所有类型(只需使用Types...)是很容易的,但如何在外部实现呢?
发布于 2019-04-20 21:13:49
你可以使用一个辅助模板来解包参数:
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);
}https://stackoverflow.com/questions/55773659
复制相似问题