tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
variant< Ts > Struct Template Reference

#include <variant.hpp>

Public Member Functions

constexpr variant () noexcept(is_nothrow_default_constructible_v< first_type >)
 
template<size_t I, typename... Args>
requires ((I < sizeof...(Ts)) and is_constructible_v<variant_alternative_t<I, variant>, Args...>)
constexpr variant (in_place_index_t< I >, Args &&... args)
 
template<typename T, typename... Args>
requires (is_constructible_v<T, Args...> and meta::count_v<remove_cvref_t<T>, meta::list<Ts...>> == 1)
constexpr variant (in_place_type_t< T >, Args &&... args)
 
template<typename T>
requires ( (sizeof...(Ts) > 0) and not is_same_v<remove_cvref_t<T>, variant> and not detail::is_in_place_index<remove_cvref_t<T>> and not detail::is_in_place_type<remove_cvref_t<T>> and is_constructible_v<detail::variant_alternative_selector_t<T, Ts...>, T> )
constexpr variant (T &&t) noexcept(is_nothrow_constructible_v< detail::variant_alternative_selector_t< T, Ts... >, T >)
 
constexpr variant (variant &&)=default
 
constexpr variant (variant &&other) noexcept((... and is_nothrow_move_constructible_v< Ts >))
 
constexpr variant (variant const &)=default
 
constexpr variant (variant const &other) noexcept((... and etl::is_nothrow_copy_constructible_v< Ts >))
 
constexpr ~variant ()
 
 ~variant ()=default
 
template<typename T, typename... Args>
requires (is_constructible_v<T, Args...> and meta::count_v<T, meta::list<Ts...>> == 1)
constexpr auto emplace (Args &&... args) -> auto &
 
template<size_t I, typename... Args>
requires is_constructible_v<meta::at_t<I, meta::list<Ts...>>, Args...>
constexpr auto emplace (Args &&... args) -> auto &
 
constexpr auto index () const noexcept -> size_t
 Returns the zero-based index of the alternative that is currently held by the variant.
 
template<typename T>
requires (not is_same_v<remove_cvref_t<T>, variant> and is_assignable_v<detail::variant_alternative_selector_t<T, Ts...>&, T> and is_assignable_v<detail::variant_alternative_selector_t<T, Ts...>, T>)
constexpr auto operator= (T &&t) noexcept((is_nothrow_assignable_v< detail::variant_alternative_selector_t< T, Ts... > &, T > and is_nothrow_constructible_v< detail::variant_alternative_selector_t< T, Ts... >, T >)) -> variant &
 
constexpr auto operator= (variant &&) -> variant &=default
 
constexpr auto operator= (variant &&other) noexcept((... and is_nothrow_move_assignable_v< Ts >) and(... and is_nothrow_move_constructible_v< Ts >)) -> variant &requires((... and detail::variant_move_assignable< Ts >) and !(... and detail::variant_trivially_move_assignable< Ts >))
 
constexpr auto operator= (variant const &) -> variant &=default
 
constexpr auto operator= (variant const &other) noexcept((... and is_nothrow_copy_assignable_v< Ts >) and(... and is_nothrow_copy_constructible_v< Ts >)) -> variant &requires((... and detail::variant_copy_assignable< Ts >) and not(... and detail::variant_trivially_copy_assignable< Ts >))
 
template<size_t I>
constexpr auto operator[] (index_constant< I > index) &&-> auto &&
 Returns a reference to the object stored in the variant.
 
template<size_t I>
constexpr auto operator[] (index_constant< I > index) &-> auto &
 Returns a reference to the object stored in the variant.
 
template<size_t I>
constexpr auto operator[] (index_constant< I > index) const &&-> auto const &&
 Returns a reference to the object stored in the variant.
 
template<size_t I>
constexpr auto operator[] (index_constant< I > index) const &-> auto const &
 Returns a reference to the object stored in the variant.
 

Friends

constexpr auto operator< (variant const &lhs, variant const &rhs) -> bool
 Less-than operator.
 
constexpr auto operator<= (variant const &lhs, variant const &rhs) -> bool
 Less-equal operator.
 
constexpr auto operator== (variant const &lhs, variant const &rhs) -> bool
 Equality operator.
 
constexpr auto operator> (variant const &lhs, variant const &rhs) -> bool
 Greater-than operator.
 
constexpr auto operator>= (variant const &lhs, variant const &rhs) -> bool
 Greater-equal operator.
 

Related Symbols

(Note that these are not member symbols.)

template<typename T, typename... Ts>
constexpr auto get_if (variant< Ts... > *pv) noexcept -> add_pointer_t< T >
 Type-based non-throwing accessor: The call is ill-formed if T is not a unique element of Ts....
 
template<size_t I, typename... Ts>
constexpr auto get_if (variant< Ts... > *pv) noexcept -> add_pointer_t< variant_alternative_t< I, variant< Ts... > > >
 If pv is not a null pointer and pv->index() == I, returns a pointer to the value stored in the variant pointed to by pv. Otherwise, returns a null pointer value. The call is ill-formed if I is not a valid index in the variant.
 
template<typename T, typename... Ts>
constexpr auto get_if (variant< Ts... > const *pv) noexcept -> add_pointer_t< T const >
 Type-based non-throwing accessor: The call is ill-formed if T is not a unique element of Ts....
 
template<size_t I, typename... Ts>
constexpr auto get_if (variant< Ts... > const *pv) noexcept -> add_pointer_t< variant_alternative_t< I, variant< Ts... > > const >
 If pv is not a null pointer and pv->index() == I, returns a pointer to the value stored in the variant pointed to by pv. Otherwise, returns a null pointer value. The call is ill-formed if I is not a valid index in the variant.
 
template<typename T, typename... Ts>
constexpr auto holds_alternative (variant< Ts... > const &v) noexcept -> bool
 Checks if the variant v holds the alternative T. The call is ill-formed if T does not appear exactly once in Ts...
 
template<size_t I, typename... Ts>
constexpr auto unchecked_get (variant< Ts... > &&v) -> auto &&
 Returns a reference to the object stored in the variant.
 
template<size_t I, typename... Ts>
constexpr auto unchecked_get (variant< Ts... > &v) -> auto &
 Returns a reference to the object stored in the variant.
 
template<size_t I, typename... Ts>
constexpr auto unchecked_get (variant< Ts... > const &&v) -> auto const &&
 Returns a reference to the object stored in the variant.
 
template<size_t I, typename... Ts>
constexpr auto unchecked_get (variant< Ts... > const &v) -> auto const &
 Returns a reference to the object stored in the variant.
 
template<typename F, typename... Vs>
constexpr auto visit (F &&f, Vs &&... vs)
 Applies the visitor vis (Callable that can be called with any combination of types from variants) to the variants vars.
 
template<typename F, typename... Vs>
constexpr auto visit_with_index (F &&f, Vs &&... vs)
 Applies the visitor vis (Callable that can be called with any combination of types from variants) to the variants vars.
 

Constructor & Destructor Documentation

◆ variant() [1/8]

template<typename... Ts>
variant ( )
inlineconstexprnoexcept

◆ variant() [2/8]

template<typename... Ts>
template<typename T>
requires ( (sizeof...(Ts) > 0) and not is_same_v<remove_cvref_t<T>, variant> and not detail::is_in_place_index<remove_cvref_t<T>> and not detail::is_in_place_type<remove_cvref_t<T>> and is_constructible_v<detail::variant_alternative_selector_t<T, Ts...>, T> )
variant ( T && t)
inlineconstexprnoexcept

◆ variant() [3/8]

template<typename... Ts>
template<size_t I, typename... Args>
requires ((I < sizeof...(Ts)) and is_constructible_v<variant_alternative_t<I, variant>, Args...>)
variant ( in_place_index_t< I > ,
Args &&... args )
inlineexplicitconstexpr

◆ variant() [4/8]

template<typename... Ts>
template<typename T, typename... Args>
requires (is_constructible_v<T, Args...> and meta::count_v<remove_cvref_t<T>, meta::list<Ts...>> == 1)
variant ( in_place_type_t< T > ,
Args &&... args )
inlineexplicitconstexpr

◆ variant() [5/8]

template<typename... Ts>
variant ( variant< Ts > const & )
constexprdefault

◆ variant() [6/8]

template<typename... Ts>
variant ( variant< Ts > const & other)
inlineconstexprnoexcept

◆ variant() [7/8]

template<typename... Ts>
variant ( variant< Ts > && )
constexprdefault

◆ variant() [8/8]

template<typename... Ts>
variant ( variant< Ts > && other)
inlineconstexprnoexcept

◆ ~variant() [1/2]

template<typename... Ts>
~variant ( )
default

◆ ~variant() [2/2]

template<typename... Ts>
~variant ( )
inlineconstexpr

Member Function Documentation

◆ emplace() [1/2]

template<typename... Ts>
template<typename T, typename... Args>
requires (is_constructible_v<T, Args...> and meta::count_v<T, meta::list<Ts...>> == 1)
auto emplace ( Args &&... args) -> auto&
inlineconstexpr

◆ emplace() [2/2]

template<typename... Ts>
template<size_t I, typename... Args>
requires is_constructible_v<meta::at_t<I, meta::list<Ts...>>, Args...>
auto emplace ( Args &&... args) -> auto&
inlineconstexpr

◆ index()

template<typename... Ts>
auto index ( ) const -> size_t
inlinenodiscardconstexprnoexcept

Returns the zero-based index of the alternative that is currently held by the variant.

◆ operator=() [1/5]

template<typename... Ts>
template<typename T>
requires (not is_same_v<remove_cvref_t<T>, variant> and is_assignable_v<detail::variant_alternative_selector_t<T, Ts...>&, T> and is_assignable_v<detail::variant_alternative_selector_t<T, Ts...>, T>)
auto operator= ( T && t) -> variant&
inlineconstexprnoexcept

◆ operator=() [2/5]

template<typename... Ts>
auto operator= ( variant< Ts > && ) -> variant &=default
constexprdefault

◆ operator=() [3/5]

template<typename... Ts>
auto operator= ( variant< Ts > && other) -> variant& requires( (... and detail::variant_move_assignable<Ts>) and !(... and detail::variant_trivially_move_assignable<Ts>) )
inlineconstexprnoexcept

◆ operator=() [4/5]

template<typename... Ts>
auto operator= ( variant< Ts > const & ) -> variant &=default
constexprdefault

◆ operator=() [5/5]

template<typename... Ts>
auto operator= ( variant< Ts > const & other) -> variant& requires( (... and detail::variant_copy_assignable<Ts>) and not(... and detail::variant_trivially_copy_assignable<Ts>) )
inlineconstexprnoexcept

◆ operator[]() [1/4]

template<typename... Ts>
template<size_t I>
auto operator[] ( index_constant< I > index) && -> auto&&
inlineconstexpr

Returns a reference to the object stored in the variant.

Precondition
I == index()

◆ operator[]() [2/4]

template<typename... Ts>
template<size_t I>
auto operator[] ( index_constant< I > index) & -> auto&
inlineconstexpr

Returns a reference to the object stored in the variant.

Precondition
I == index()

◆ operator[]() [3/4]

template<typename... Ts>
template<size_t I>
auto operator[] ( index_constant< I > index) const && -> auto const&&
inlineconstexpr

Returns a reference to the object stored in the variant.

Precondition
I == index()

◆ operator[]() [4/4]

template<typename... Ts>
template<size_t I>
auto operator[] ( index_constant< I > index) const & -> auto const&
inlineconstexpr

Returns a reference to the object stored in the variant.

Precondition
I == index()

Friends And Related Symbol Documentation

◆ get_if() [1/4]

template<typename T, typename... Ts>
auto get_if ( variant< Ts... > * pv) -> add_pointer_t<T>
related

Type-based non-throwing accessor: The call is ill-formed if T is not a unique element of Ts....

◆ get_if() [2/4]

template<size_t I, typename... Ts>
auto get_if ( variant< Ts... > * pv) -> add_pointer_t<variant_alternative_t<I, variant<Ts...>>>
related

If pv is not a null pointer and pv->index() == I, returns a pointer to the value stored in the variant pointed to by pv. Otherwise, returns a null pointer value. The call is ill-formed if I is not a valid index in the variant.

◆ get_if() [3/4]

template<typename T, typename... Ts>
auto get_if ( variant< Ts... > const * pv) -> add_pointer_t<T const>
related

Type-based non-throwing accessor: The call is ill-formed if T is not a unique element of Ts....

◆ get_if() [4/4]

template<size_t I, typename... Ts>
auto get_if ( variant< Ts... > const * pv) -> add_pointer_t<variant_alternative_t<I, variant<Ts...>> const>
related

If pv is not a null pointer and pv->index() == I, returns a pointer to the value stored in the variant pointed to by pv. Otherwise, returns a null pointer value. The call is ill-formed if I is not a valid index in the variant.

◆ holds_alternative()

template<typename T, typename... Ts>
auto holds_alternative ( variant< Ts... > const & v) -> bool
related

Checks if the variant v holds the alternative T. The call is ill-formed if T does not appear exactly once in Ts...

◆ operator<

template<typename... Ts>
auto operator< ( variant< Ts > const & lhs,
variant< Ts > const & rhs ) -> bool
friend

Less-than operator.

  • If lhs.index() < rhs.index(), returns true;
  • If lhs.index() > rhs.index(), returns false;
  • Otherwise returns get<lhs.index()>(v) < get<lhs.index()>(w)

◆ operator<=

template<typename... Ts>
auto operator<= ( variant< Ts > const & lhs,
variant< Ts > const & rhs ) -> bool
friend

Less-equal operator.

  • If lhs.index() < rhs.index(), returns true;
  • If lhs.index() > rhs.index(), returns false;
  • Otherwise returns get<lhs.index()>(v) <= get<lhs.index()>(w)

◆ operator==

template<typename... Ts>
auto operator== ( variant< Ts > const & lhs,
variant< Ts > const & rhs ) -> bool
friend

Equality operator.

  • If lhs.index() != rhs.index(), returns false;
  • Otherwise returns get<lhs.index()>(lhs) == get<lhs.index()>(rhs)

◆ operator>

template<typename... Ts>
auto operator> ( variant< Ts > const & lhs,
variant< Ts > const & rhs ) -> bool
friend

Greater-than operator.

  • If lhs.index() > rhs.index(), returns true;
  • If lhs.index() < rhs.index(), returns false;
  • Otherwise returns get<lhs.index()>(v) > get<lhs.index()>(w)

◆ operator>=

template<typename... Ts>
auto operator>= ( variant< Ts > const & lhs,
variant< Ts > const & rhs ) -> bool
friend

Greater-equal operator.

  • If lhs.index() > rhs.index(), returns true;
  • If lhs.index() < rhs.index(), returns false;
  • Otherwise returns get<lhs.index()>(v) >= get<lhs.index()>(w)

◆ unchecked_get() [1/4]

template<size_t I, typename... Ts>
auto unchecked_get ( variant< Ts... > && v) -> auto&&
related

Returns a reference to the object stored in the variant.

Precondition
v.index() == I

◆ unchecked_get() [2/4]

template<size_t I, typename... Ts>
auto unchecked_get ( variant< Ts... > & v) -> auto&
related

Returns a reference to the object stored in the variant.

Precondition
v.index() == I

◆ unchecked_get() [3/4]

template<size_t I, typename... Ts>
auto unchecked_get ( variant< Ts... > const && v) -> auto const&&
related

Returns a reference to the object stored in the variant.

Precondition
v.index() == I

◆ unchecked_get() [4/4]

template<size_t I, typename... Ts>
auto unchecked_get ( variant< Ts... > const & v) -> auto const&
related

Returns a reference to the object stored in the variant.

Precondition
v.index() == I

The documentation for this struct was generated from the following files: