20 General utilities library [utilities]

20.7 Variants [variant]

20.7.3 variant helper classes [variant.helper]

template <class T> struct variant_size;

Remarks: All specializations of variant_size<T> shall meet the UnaryTypeTrait requirements ([meta.rqmts]) with a BaseCharacteristic of integral_constant<size_t, N> for some N.

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>;

Let VS denote variant_size<T> of the cv-unqualified type T. Then each of the three templates shall meet the UnaryTypeTrait requirements ([meta.rqmts]) with a BaseCharacteristic of integral_constant<size_t, VS::value>.

template <class... Types> struct variant_size<variant<Types...>> : integral_constant<size_t, sizeof...(Types)> { }; template <size_t I, class T> class variant_alternative<I, const T>; template <size_t I, class T> class variant_alternative<I, volatile T>; template <size_t I, class T> class variant_alternative<I, const volatile T>;

Let VA denote variant_alternative<I, T> of the cv-unqualified type T. Then each of the three templates shall meet the TransformationTrait requirements ([meta.rqmts]) with a member typedef type that names the following type:

  • for the first specialization, add_const_t<VA::type>,

  • for the second specialization, add_volatile_t<VA::type>, and

  • for the third specialization, add_cv_t<VA::type>.

variant_alternative<I, variant<Types...>>::type

Requires: I < sizeof...(Types).

Value: The type TI.