[variant.syn] # 22 General utilities library [[utilities]](./#utilities) ## 22.6 Variants [[variant]](variant#syn) ### 22.6.2 Header synopsis [variant.syn] // mostly freestanding#include // see [[compare.syn]](compare.syn "17.12.1 Header synopsis")namespace std {// [[variant.variant]](variant.variant "22.6.3 Class template variant"), class template varianttemplateclass variant; // [[variant.helper]](variant.helper "22.6.4 variant helper classes"), variant helper classestemplate struct variant_size; // *not defined*template struct variant_size; templateconstexpr size_t [variant_size_v](#lib:variant_size_v "22.6.2 Header synopsis [variant.syn]") = variant_size::value; templatestruct variant_size>; template struct variant_alternative; // *not defined*template struct variant_alternative; templateusing [variant_alternative_t](#lib:variant_alternative_t "22.6.2 Header synopsis [variant.syn]") = typename variant_alternative::type; templatestruct variant_alternative>; inline constexpr size_t variant_npos = -1; // [[variant.get]](variant.get "22.6.5 Value access"), value accesstemplateconstexpr bool holds_alternative(const variant&) noexcept; templateconstexpr variant_alternative_t>& get(variant&); // freestanding-deletedtemplateconstexpr variant_alternative_t>&& get(variant&&); // freestanding-deletedtemplateconstexpr const variant_alternative_t>& get(const variant&); // freestanding-deletedtemplateconstexpr const variant_alternative_t>&& get(const variant&&); // freestanding-deletedtemplateconstexpr T& get(variant&); // freestanding-deletedtemplateconstexpr T&& get(variant&&); // freestanding-deletedtemplateconstexpr const T& get(const variant&); // freestanding-deletedtemplateconstexpr const T&& get(const variant&&); // freestanding-deletedtemplateconstexpr add_pointer_t>> get_if(variant*) noexcept; templateconstexpr add_pointer_t>> get_if(const variant*) noexcept; templateconstexpr add_pointer_t get_if(variant*) noexcept; templateconstexpr add_pointer_t get_if(const variant*) noexcept; // [[variant.relops]](variant.relops "22.6.6 Relational operators"), relational operatorstemplateconstexpr bool operator==(const variant&, const variant&); templateconstexpr bool operator!=(const variant&, const variant&); templateconstexpr bool operator<(const variant&, const variant&); templateconstexpr bool operator>(const variant&, const variant&); templateconstexpr bool operator<=(const variant&, const variant&); templateconstexpr bool operator>=(const variant&, const variant&); template requires ([three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_­way_­comparable [cmp.concept]") && ...)constexpr common_comparison_category_t...>operator<=>(const variant&, const variant&); // [[variant.visit]](variant.visit "22.6.7 Visitation"), visitationtemplateconstexpr *see below* visit(Visitor&&, Variants&&...); templateconstexpr 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 algorithmstemplateconstexpr void swap(variant&, variant&) 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 struct hash; template struct hash>; template<> struct hash;}