考虑以下示例:
#include <iostream>
#include <type_traits>
template <typename Type>
struct Something
{
template <typename OtherType>
static constexpr bool same()
{return std::is_same<Type, OtherType>::value;}
};
template <class Type>
struct Example
{
static_assert(Type::template same<double>(), "ERROR");
};
int main()
{
Example<Something<double>> example;
return 0;
}
通过执行函数static_assert
检查传递的类型是否满足某些条件。same()
现在考虑可以将多个传递Types
给Example
:
#include <iostream>
#include <type_traits>
template <typename Type>
struct Something
{
template <typename OtherType>
static constexpr bool same()
{return std::is_same<Type, OtherType>::value;}
};
template <class... Types>
struct Example
{
static_assert(/* SOMETHING */, "ERROR");
};
int main()
{
Example<Something<double>> example;
return 0;
}
是否有一种有效的语法,而不是SOMETHING
检查条件是否在所有类型上都得到验证(没有一堆辅助函数:我知道可以通过这种方式完成,但我想知道是否有另一种方式(比如在某处使用简单的解包。 ..))