[variant.status]

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

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

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

#### 22.6.3.6 Value status [variant.status]

[ð](#lib:valueless_by_exception,variant)

`constexpr bool valueless_by_exception() const noexcept;
`

[1](#1)

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

*Effects*: Returns false if and only if the variant holds a value[.](#1.sentence-1)

[2](#2)

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

[*Note [1](#note-1)*:

It is possible for a variant to hold no value
if an exception is thrown during a
type-changing assignment or emplacement[.](#2.sentence-1)

The latter means that even avariant<float, int> can become valueless_by_exception(), for
instance bystruct S { operator int() { throw 42; }};
variant<float, int> v{12.f};
v.emplace<1>(S());

â *end note*]

[ð](#lib:index,variant)

`constexpr size_t index() const noexcept;
`

[3](#3)

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

*Effects*: If valueless_by_exception() is true, returns variant_npos[.](#3.sentence-1)

Otherwise, returns the zero-based index of the alternative of the contained value[.](#3.sentence-2)
