3.7.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
TypesThe list of element types. It may not contain dupiicates.

See fcppt.variant for more information.

Public Types

using this_type = fcppt::variant::object< Types... >
 
using types = ::metal::list< Types... >
 The metal::list of the possible types. More...
 
using std_type = fcppt::variant::detail::std_type< types >
 

Public Member Functions

template<typename U , typename = std::enable_if_t<fcppt::variant::detail:: has_type<this_type, fcppt::type_traits::remove_cv_ref_t<U>>::value>>
 object (U &&)
 Constructs the variant from a value. 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...
 
std_typeimpl ()
 
std_type const & impl () const
 

Member Typedef Documentation

◆ std_type

template<typename... Types>
using fcppt::variant::object< Types >::std_type = fcppt::variant::detail::std_type<types>

◆ this_type

template<typename... Types>
using fcppt::variant::object< Types >::this_type = fcppt::variant::object<Types...>

◆ types

template<typename... Types>
using fcppt::variant::object< Types >::types = ::metal::list<Types...>

The metal::list of the possible types.

Constructor & Destructor Documentation

◆ object()

template<typename... Types>
template<typename U , typename = std::enable_if_t<fcppt::variant::detail:: has_type<this_type, fcppt::type_traits::remove_cv_ref_t<U>>::value>>
fcppt::variant::object< Types >::object ( U &&  )
explicit

Constructs the variant from a value.

Constructs the variant from value.

Template Parameters
UMust be a type among types

Member Function Documentation

◆ get_unsafe() [1/2]

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

Returns a reference to the held type without any checks.

Template Parameters
UMust be a type among types
Warning
The behaviour is undefined if the variant does not contain U.

◆ get_unsafe() [2/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.

Template Parameters
UMust be a type among types
Warning
The behaviour is undefined if the variant does not contain U.

◆ impl() [1/2]

template<typename... Types>
std_type& fcppt::variant::object< Types >::impl ( )

◆ impl() [2/2]

template<typename... Types>
std_type const& fcppt::variant::object< Types >::impl ( ) const

◆ 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.

◆ 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.