[variant.variant.general]

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

## 22.6 Variants [[variant]](variant#variant.general)

### 22.6.3 Class template variant [[variant.variant]](variant.variant#general)

#### 22.6.3.1 General [variant.variant.general]

namespace std {template<class... Types>class variant {public:// [[variant.ctor]](variant.ctor "22.6.3.2 Constructors"), constructorsconstexpr variant() noexcept(*see below*); constexpr variant(const variant&); constexpr variant(variant&&) noexcept(*see below*); template<class T>constexpr variant(T&&) noexcept(*see below*); template<class T, class... Args>constexpr explicit variant(in_place_type_t<T>, Args&&...); template<class T, class U, class... Args>constexpr explicit variant(in_place_type_t<T>, initializer_list<U>, Args&&...); template<size_t I, class... Args>constexpr explicit variant(in_place_index_t<I>, Args&&...); template<size_t I, class U, class... Args>constexpr explicit variant(in_place_index_t<I>, initializer_list<U>, Args&&...); // [[variant.dtor]](variant.dtor "22.6.3.3 Destructor"), destructorconstexpr ~variant(); // [[variant.assign]](variant.assign "22.6.3.4 Assignment"), assignmentconstexpr variant& operator=(const variant&); constexpr variant& operator=(variant&&) noexcept(*see below*); template<class T> constexpr variant& operator=(T&&) noexcept(*see below*); // [[variant.mod]](variant.mod "22.6.3.5 Modifiers"), modifierstemplate<class T, class... Args>constexpr T& emplace(Args&&...); template<class T, class U, class... Args>constexpr T& emplace(initializer_list<U>, Args&&...); template<size_t I, class... Args>constexpr variant_alternative_t<I, variant<Types...>>& emplace(Args&&...); template<size_t I, class U, class... Args>constexpr variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U>, Args&&...); // [[variant.status]](variant.status "22.6.3.6 Value status"), value statusconstexpr bool valueless_by_exception() const noexcept; constexpr size_t index() const noexcept; // [[variant.swap]](variant.swap "22.6.3.7 Swap"), swapconstexpr void swap(variant&) noexcept(*see below*); // [[variant.visit]](variant.visit "22.6.7 Visitation"), visitationtemplate<class Self, class Visitor>constexpr decltype(auto) visit(this Self&&, Visitor&&); template<class R, class Self, class Visitor>constexpr R visit(this Self&&, Visitor&&); };}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5722)

Any instance of variant at any given time either holds a value
of one of its alternative types or holds no value[.](#1.sentence-1)

When an instance of variant holds a value of alternative type T,
it means that a value of type T, referred to as the variant object's [*contained value*](#def:contained_value,variant "22.6.3.1 General [variant.variant.general]"),
is nested within ([[intro.object]](intro.object "6.8.2 Object model")) thevariant object[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5731)

All types in Types shall meet
the [*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements"))[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5735)

A program that instantiates the definition of variant with
no template arguments is ill-formed[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5739)

If a program declares an explicit or partial specialization of variant,
the program is ill-formed, no diagnostic required[.](#4.sentence-1)
