|
variant
A type safe generalized union type
|
A type safe generalized union. More...
#include <variant.hpp>
Public Types | |
| typedef variant_storage< Types... > | storage_t |
| The underlying variant_storage type. | |
Public Member Functions | |
| variant () noexcept(std::is_nothrow_constructible< storage_t, std::integral_constant< std::size_t, 0 > >::value) | |
Default construct this variant using the first type in Types. More... | |
| variant (const variant &other) noexcept(detail::and_< std::is_nothrow_copy_constructible< Types >... >::value) | |
Copy constructor, invokes the copy constructor of the type currently bound on other. More... | |
| variant (variant &&other) noexcept(detail::and_< std::is_nothrow_move_constructible< Types >... >::value) | |
Move constructor, invokes the move constructor of the type currently bound on other. More... | |
| template<class... OtherTypes> | |
| variant (const variant< OtherTypes...> &other) noexcept(detail::and_< std::is_nothrow_copy_constructible< OtherTypes >... >::value) | |
| Copy from a compatible variant. More... | |
| template<class... OtherTypes> | |
| variant (variant< OtherTypes...> &&other) noexcept(detail::and_< std::is_nothrow_move_constructible< OtherTypes >... >::value) | |
| Move from a compatible variant. More... | |
| template<class T > | |
| variant (T &&value) noexcept(std::is_nothrow_constructible< storage_t, deduce_overload_t< T && >, T && >::value) | |
| Generic constructor, tries to deduce the desired type. More... | |
| template<class T > | |
| variant (std::initializer_list< T > init_list) noexcept(std::is_nothrow_constructible< storage_t, deduce_overload_t< std::initializer_list< T > >, std::initializer_list< T > >::value) | |
| Initializer list constructor, tries to deduce the desired type. More... | |
| ~variant () noexcept(detail::and_< std::is_nothrow_destructible< Types >... >::value) | |
| Destructor, calls the destructor on the currently bound type. More... | |
| variant & | operator= (const variant &other) noexcept(detail::and_< std::is_nothrow_copy_assignable< Types >..., std::is_nothrow_copy_constructible< Types >... >::value) |
| Copy assignment operator. More... | |
| variant & | operator= (variant &&other) noexcept(detail::and_< std::is_nothrow_move_assignable< Types >... >::value) |
| Move assignment operator. More... | |
| std::size_t | which () const noexcept |
| Return the index of the current bound object. | |
| const std::type_info & | type () const noexcept |
| Return the type_info of the current bound object. | |
Friends | |
| template<class T , class Variant , class = typename std::enable_if< std::is_same< variant, typename std::decay< Variant >::type >::value >::type> | |
| variant_element_t< variant_index< T, Variant >::value, Variant > | get (Variant &&v) |
| Return a reference to the current bound object. More... | |
A type safe generalized union.
This class stores exactly one object of one of the type in Types. Like boost::variant , this class provides the never empty guarantee.
Difference between this class and a href = http://www.boost.org/doc/libs/1_57_0>boost::variant :
LessThanComparable, even if all the Types are. We believe that comparison on variant might be confusing, and the user is still allowed to define its own comparison operators anyway| Types | A list of types that can be stored in this variant. |
Types are all different. Types can not be references Types are not cv qualified Default construct this variant using the first type in Types.
Only available if the first type in the list of types is DefaultConstructible.
Copy constructor, invokes the copy constructor of the type currently bound on other.
Types must be copy constructible.Copy construct the value currently bound on other on this variant.
Move constructor, invokes the move constructor of the type currently bound on other.
Types must be MoveConstructible
|
inlinenoexcept |
Copy from a compatible variant.
OtherTypes Must be a subset of Types
|
inlinenoexcept |
Move from a compatible variant.
OtherTypes Must be a subset of Types Generic constructor, tries to deduce the desired type.
Use the same rules as overload resolution to determine which type in Types shall be initialized, then perfect forward the argument to the constructor of that type.
|
inlinenoexcept |
Initializer list constructor, tries to deduce the desired type.
Use the same rules as overload resolution to determine which type in Types shall be initialized, then perfect forward the arguments to the constructor of that type.
Destructor, calls the destructor on the currently bound type.
Types must be Destructible
|
inlinenoexcept |
Copy assignment operator.
Types must be CopyAssignable. Types must be NothrowDestructible. Types are NothrowCopyConstructible or all Types are NothrowMoveConstructible If which() == calls the copy assignemnt on the bound type.other.which()
Otherwise, if the type currently bound on other is NothrowCopyConstructible destroy the current bound object and reinitialize the variant using a copy of the object currently bound on other.
If the type currently bound on other is not NothrowCopyConstructible, performs a temporary copy of other, then destroy the current bound object and move the temporary copy into this.
|
inlinenoexcept |
Move assignment operator.
Types must be MoveAssignable. Types must be NothrowDestructible. Types are NothrowMoveConstructible If which() == calls the move assignemnt on the bound type.other.which()
Otherwise, destroy the current bound object and reinitialize the variant moving the object currently bound on other.
|
friend |
Return a reference to the current bound object.
| T | The expected type of the object. |
| bad_variant_access | If the precondition is not met. |
1.8.9.1