所有std::variant_size 的特化都满足以某些 N 的std::integral_constant<std::size_t, N> 为基特征的一元类型特征 (UnaryTypeTrait) 。 示例运行此代码#include <any> #include <cstdio> #include <variant> static_assert(std::variant_size_v<std...
3) 满足基特征 (BaseCharacteristic) 为 std::integral_constant<std::size_t, variant_size<T>> 的一元类型特征 (UnaryTypeTrait) 要求辅助变量模板template <class T> inline constexpr std::size_t variant_size_v = std::variant_size<T>::value; (C++17 起) ...
在标头 <variant> 定义 template< class T > struct variant_size; /* 无定义 */ (1) (C++17 起) template< class... Types > struct variant_size<std::variant<Types...>> : std::integral_constant<std::size_t, sizeof...(Types)> {}; (2) (C++17 起) template< class T > ...
3) 满足基特征 (BaseCharacteristic) 为 std::integral_constant<std::size_t, variant_size<T>> 的一元类型特征 (UnaryTypeTrait) 要求辅助变量模板template <class T> inline constexpr std::size_t variant_size_v = std::variant_size<T>::value; (C++17 起) ...
: std::integral_constant<std::size_t, sizeof...(Types)> { }; (2) (C++17 起) template <class T> class variant_size<const T>; template <class T> class variant_size<volatile T>; template <class T> class variant_size<const volatile T>; (3) (C++17 起) 提供...
(std::variant_size_v<std::variant<int, float, double>> == 3); static_assert(std::variant_size_v<std::variant<std::monostate, void>> == 2); static_assert(std::variant_size_v<std::variant<const int, const float>> == 2); static_assert(std::variant_size_v<std::variant<std::...