[variant.syn]

# 22 General utilities library [[utilities]](./#utilities)

## 22.6 Variants [[variant]](variant#syn)

### 22.6.2 Header <variant> synopsis [variant.syn]

// mostly freestanding#include <compare> // see [[compare.syn]](compare.syn "17.12.1 Header <compare> synopsis")namespace std {// [[variant.variant]](variant.variant "22.6.3 Class template variant"), class template varianttemplate<class... Types>class variant; // [[variant.helper]](variant.helper "22.6.4 variant helper classes"), variant helper classestemplate<class T> struct variant_size; // *not defined*template<class T> struct variant_size<const T>; template<class T>constexpr size_t [variant_size_v](#lib:variant_size_v "22.6.2 Header <variant> synopsis [variant.syn]") = variant_size<T>::value; template<class... Types>struct variant_size<variant<Types...>>; template<size_t I, class T> struct variant_alternative; // *not defined*template<size_t I, class T> struct variant_alternative<I, const T>; template<size_t I, class T>using [variant_alternative_t](#lib:variant_alternative_t "22.6.2 Header <variant> synopsis [variant.syn]") = typename variant_alternative<I, T>::type; template<size_t I, class... Types>struct variant_alternative<I, variant<Types...>>; inline constexpr size_t variant_npos = -1; // [[variant.get]](variant.get "22.6.5 Value access"), value accesstemplate<class T, class... Types>constexpr bool holds_alternative(const variant<Types...>&) noexcept; template<size_t I, class... Types>constexpr variant_alternative_t<I, variant<Types...>>& get(variant<Types...>&); // freestanding-deletedtemplate<size_t I, class... Types>constexpr variant_alternative_t<I, variant<Types...>>&& get(variant<Types...>&&); // freestanding-deletedtemplate<size_t I, class... Types>constexpr const variant_alternative_t<I, variant<Types...>>& get(const variant<Types...>&); // freestanding-deletedtemplate<size_t I, class... Types>constexpr const variant_alternative_t<I, variant<Types...>>&& get(const variant<Types...>&&); // freestanding-deletedtemplate<class T, class... Types>constexpr T& get(variant<Types...>&); // freestanding-deletedtemplate<class T, class... Types>constexpr T&& get(variant<Types...>&&); // freestanding-deletedtemplate<class T, class... Types>constexpr const T& get(const variant<Types...>&); // freestanding-deletedtemplate<class T, class... Types>constexpr const T&& get(const variant<Types...>&&); // freestanding-deletedtemplate<size_t I, class... Types>constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>> get_if(variant<Types...>*) noexcept; template<size_t I, class... Types>constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>> get_if(const variant<Types...>*) noexcept; template<class T, class... Types>constexpr add_pointer_t<T> get_if(variant<Types...>*) noexcept; template<class T, class... Types>constexpr add_pointer_t<const T> get_if(const variant<Types...>*) noexcept; // [[variant.relops]](variant.relops "22.6.6 Relational operators"), relational operatorstemplate<class... Types>constexpr bool operator==(const variant<Types...>&, const variant<Types...>&); template<class... Types>constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&); template<class... Types>constexpr bool operator<(const variant<Types...>&, const variant<Types...>&); template<class... Types>constexpr bool operator>(const variant<Types...>&, const variant<Types...>&); template<class... Types>constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&); template<class... Types>constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&); template<class... Types> requires ([three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_­way_­comparable [cmp.concept]")<Types> && ...)constexpr common_comparison_category_t<compare_three_way_result_t<Types>...>operator<=>(const variant<Types...>&, const variant<Types...>&); // [[variant.visit]](variant.visit "22.6.7 Visitation"), visitationtemplate<class Visitor, class... Variants>constexpr *see below* visit(Visitor&&, Variants&&...); template<class R, class Visitor, class... Variants>constexpr R visit(Visitor&&, Variants&&...); // [[variant.monostate]](variant.monostate "22.6.8 Class monostate"), class monostatestruct monostate; // [[variant.monostate.relops]](variant.monostate.relops "22.6.9 monostate relational operators"), monostate relational operatorsconstexpr bool operator==(monostate, monostate) noexcept; constexpr strong_ordering operator<=>(monostate, monostate) noexcept; // [[variant.specalg]](variant.specalg "22.6.10 Specialized algorithms"), specialized algorithmstemplate<class... Types>constexpr void swap(variant<Types...>&, variant<Types...>&) noexcept(*see below*); // [[variant.bad.access]](variant.bad.access "22.6.11 Class bad_­variant_­access"), class bad_variant_accessclass bad_variant_access; // [[variant.hash]](variant.hash "22.6.12 Hash support"), hash supporttemplate<class T> struct hash; template<class... Types> struct hash<variant<Types...>>; template<> struct hash<monostate>;}
