2.6.0
Freundlich's C++ toolkit
Public Types | Public Member Functions
fcppt::variant::object< Types > Class Template Reference

Detailed Description

template<typename Types>
class fcppt::variant::object< Types >

A class that can hold any object from a fixed set of types.

Template Parameters
TypesAn MPL sequence of types that must be CopyConstructible or Movable, Assignable or AssignMovable and complete. It therefore must also not be const.

See the module description for more information.

Public Types

typedef Types types
 An mpl sequence of the possible types. More...
 

Public Member Functions

template<typename U >
 object (U const &value)
 Constructs the variant from a value. More...
 
template<typename U >
 object (U &&value, fcppt::variant::detail::disable_object< U, object > *=nullptr)
 Move constructs the variant from a value. More...
 
 object (object const &other)
 Copy constructs a variant. More...
 
 object (object &&other) noexcept(fcppt::variant::detail::nothrow_move_constructible< Types >::value)
 Move constructs a variant. More...
 
template<typename U >
objectoperator= (U const &value)
 Assigns a new value to the variant. More...
 
template<typename U >
fcppt::variant::detail::disable_object< U, object > & operator= (U &&value)
 Move assigns a new value to the variant. More...
 
objectoperator= (object const &other)
 Assigns a variant. More...
 
objectoperator= (object &&other) noexcept(fcppt::variant::detail::nothrow_move_assignable< Types >::value)
 Move assigns a variant. More...
 
 ~object ()
 Destroys the variant. More...
 
template<typename U >
U const & get_unsafe () const
 Returns a const reference to the held type without any checks. More...
 
template<typename U >
U & get_unsafe ()
 Returns a reference to the held type without any checks. More...
 
fcppt::variant::size_type type_index () const
 Returns the index of the held type. More...
 
bool is_invalid () const
 Returns if the variant is invalid. More...
 

Member Typedef Documentation

◆ types

template<typename Types>
typedef Types fcppt::variant::object< Types >::types

An mpl sequence of the possible types.

Constructor & Destructor Documentation

◆ object() [1/4]

template<typename Types>
template<typename U >
fcppt::variant::object< Types >::object ( U const &  value)
explicit

Constructs the variant from a value.

Constructs the variant from value.

Template Parameters
UMust be a type among types

◆ object() [2/4]

template<typename Types>
template<typename U >
fcppt::variant::object< Types >::object ( U &&  value,
fcppt::variant::detail::disable_object< U, object< Types > > *  = nullptr 
)
explicit

Move constructs the variant from a value.

Move constructs the variant from value.

Template Parameters
UMust be a type among types

◆ object() [3/4]

template<typename Types>
fcppt::variant::object< Types >::object ( object< Types > const &  other)

Copy constructs a variant.

Copy constructs the value held by other into the variant.

◆ object() [4/4]

template<typename Types>
fcppt::variant::object< Types >::object ( object< Types > &&  other) const
noexcept

Move constructs a variant.

Move constructs the value held by other into the variant.

◆ ~object()

template<typename Types>
fcppt::variant::object< Types >::~object ( )

Destroys the variant.

Calls the destructor of the held value.

Member Function Documentation

◆ get_unsafe() [1/2]

template<typename Types>
template<typename U >
U const& fcppt::variant::object< Types >::get_unsafe ( ) const

Returns a const reference to the held type without any checks.

If fcppt::mpl::index_of<types, U>::value == this->type_index() is true, a const reference to currently held value is be returned.

Template Parameters
UMust be a type among types
Warning
The behaviour is undefined if fcppt::mpl::index_of<types, U>::value == this->type_index() is false.

◆ get_unsafe() [2/2]

template<typename Types>
template<typename U >
U& fcppt::variant::object< Types >::get_unsafe ( )

Returns a reference to the held type without any checks.

If fcppt::mpl::index_of<types, U>::value == this->type_index() is true, a reference to currently held value is be returned.

Template Parameters
UMust be a type among types
Warning
The behaviour is undefined if fcppt::mpl::index_of<types, U>::value == this->type_index() is false.

◆ is_invalid()

template<typename Types>
bool fcppt::variant::object< Types >::is_invalid ( ) const

Returns if the variant is invalid.

This can only happen if an assignment of a different type throws an exception. There is no way to recover from that, except for falling back to heap allocation. An invalid variant should only be destroyed or assigned to.

◆ operator=() [1/4]

template<typename Types>
template<typename U >
object& fcppt::variant::object< Types >::operator= ( U const &  value)

Assigns a new value to the variant.

Assigns value to the variant. Calls the assignment operator of the held type when possible.

Template Parameters
UMust be a type among types

◆ operator=() [2/4]

template<typename Types>
template<typename U >
fcppt::variant::detail::disable_object< U, object >& fcppt::variant::object< Types >::operator= ( U &&  value)

Move assigns a new value to the variant.

Move assigns value to the variant. Calls the move assignment operator of the held type when possible.

◆ operator=() [3/4]

template<typename Types>
object& fcppt::variant::object< Types >::operator= ( object< Types > const &  other)

Assigns a variant.

Assigns the value from other to the variant. Calls the assignment operator of the held type when possible.

◆ operator=() [4/4]

template<typename Types>
object& fcppt::variant::object< Types >::operator= ( object< Types > &&  other)
noexcept

Move assigns a variant.

Move assigns the value from other to the variant. Calls the move assignment operator of the held type when possible.

◆ type_index()

template<typename Types>
fcppt::variant::size_type fcppt::variant::object< Types >::type_index ( ) const

Returns the index of the held type.

Returns
A runtime index into types of the held type.