constexpr bool valueless_by_exception() const; | (since C++17) |
Returns false
if and only if the variant holds a value.
noexcept
specification: noexcept
A variant may become valueless in the following situations:
Since variant is never permitted to allocate dynamic memory, previous value cannot be retained in these situations.
This applies even to variants of non-class types:
struct S { operator int() { throw 42; } }; variant<float, int> v{12.f}; // OK v.emplace<1>(S()); // v may be valueless
A variant that is valueless by exception is treated as being in an invalid state: index returns variant_npos, get and visit throw bad_variant_access.
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/variant/valueless_by_exception