join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::Variant< Ts > Class Template Reference

variant class. More...

#include <variant.hpp>

Public Member Functions

constexpr Variant ()
 default constructor.
 
constexpr Variant (const Variant &other)=default
 copy constructor.
 
constexpr Variant (const Variant &other)
 copy constructor.
 
constexpr Variant (Variant &&other)=default
 move constructor.
 
constexpr Variant (Variant &&other) noexcept
 move constructor.
 
template<typename T , typename Match = match_t<T&&, Ts...>>
requires is_unique_v<Match, Ts...> && std::is_constructible_v<Match, T&&>
constexpr Variant (T &&t)
 constructs a Variant holding the alternative selected by overload resolution.
 
template<typename T , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, Args&&...>
constexpr Variant (std::in_place_type_t< T >, Args &&... args)
 constructs a Variant with the specified alternative T.
 
template<typename T , typename Up , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, std::initializer_list<Up>&, Args&&...>
constexpr Variant (std::in_place_type_t< T >, std::initializer_list< Up > il, Args &&... args)
 constructs a Variant with the specified alternative T.
 
template<std::size_t I, typename... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, Args&&...>
constexpr Variant (std::in_place_index_t< I >, Args &&... args)
 constructs a variant with the alternative T specified by the index I.
 
template<std::size_t I, typename Up , typename... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, std::initializer_list<Up>&, Args&&...>
constexpr Variant (std::in_place_index_t< I >, std::initializer_list< Up > il, Args &&... args)
 constructs a variant with the alternative T specified by the index I.
 
 ~Variant ()=default
 destroy the Variant instance.
 
 ~Variant ()
 destroy the Variant instance.
 
constexpr Variant & operator= (const Variant &other)=default
 copy assignment.
 
constexpr Variant & operator= (const Variant &other)
 copy assignment.
 
constexpr Variant & operator= (Variant &&other)=default
 move assignment.
 
constexpr Variant & operator= (Variant &&other) noexcept
 move assignment.
 
template<typename T , typename Match = match_t<T&&, Ts...>>
requires is_unique_v<Match, Ts...> && std::is_constructible_v<Match, T&&>
constexpr Variant & operator= (T &&t)
 assign a Variant holding the alternative selected by overload resolution.
 
template<typename T >
requires is_unique_v<T, Ts...>
constexpr bool is () const
 check that the member type in use is the same than the one specified.
 
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr bool is () const
 check that the index in use is the same than the one specified.
 
template<typename T , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, Args&&...>
constexpr T & set (Args &&... args)
 set the variable type of the object identified by type and assign it a value.
 
template<typename T , typename Up , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, std::initializer_list<Up>&, Args&&...>
constexpr T & set (std::initializer_list< Up > il, Args &&... args)
 set the variable type of the object identified by type and assign it a value.
 
template<std::size_t I, typename... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, Args&&...>
constexpr std::tuple_element_t< I, std::tuple< Ts... > > & set (Args &&... args)
 set the variable type of the object identified by index and assign it a value.
 
template<std::size_t I, class Up , class... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, std::initializer_list<Up>&, Args&&...>
constexpr std::tuple_element_t< I, std::tuple< Ts... > > & set (std::initializer_list< Up > il, Args &&... args)
 set the variable type of the object identified by index and assign it a value.
 
template<typename T >
requires is_unique_v<T, Ts...>
constexpr T & get ()
 get the variable value of the object type identified by type.
 
template<typename T >
requires is_unique_v<T, Ts...>
constexpr const T & get () const
 get the variable value of the object type identified by type.
 
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr std::tuple_element_t< I, std::tuple< Ts... > > & get ()
 get the variable value of the object type identified by index.
 
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr const std::tuple_element_t< I, std::tuple< Ts... > > & get () const
 get the variable value of the object type identified by index.
 
template<typename T >
requires is_unique_v<T, Ts...>
constexpr T * getIf ()
 get the variable value address of the object type identified by type.
 
template<typename T >
requires is_unique_v<T, Ts...>
constexpr const T * getIf () const
 get the variable value address of the object type identified by type.
 
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr std::tuple_element_t< I, std::tuple< Ts... > > * getIf ()
 get the variable value address of the object type identified by index.
 
template<std::size_t I>
requires (I < sizeof...(Ts))
constexpr const std::tuple_element_t< I, std::tuple< Ts... > > * getIf () const
 get the variable value address of the object type identified by index.
 
constexpr std::size_t index () const noexcept
 return the index of the alternative that is currently held by the variant.
 
void swap (Variant &other) noexcept
 swap this variant with another.
 

Protected Member Functions

constexpr bool equal (const Variant &rhs) const
 check if equal.
 
constexpr auto compare (const Variant &rhs) const
 three-way compare.
 

Friends

template<typename... _Ts>
constexpr bool operator== (const Variant< _Ts... > &lhs, const Variant< _Ts... > &rhs)
 
template<typename... _Ts>
constexpr details::VariantOrdering< _Ts... > operator<=> (const Variant< _Ts... > &lhs, const Variant< _Ts... > &rhs)
 

Detailed Description

template<typename... Ts>
class join::Variant< Ts >

variant class.

Constructor & Destructor Documentation

◆ Variant() [1/10]

template<typename... Ts>
join::Variant< Ts >::Variant ( )
inlineconstexpr

default constructor.

◆ Variant() [2/10]

template<typename... Ts>
join::Variant< Ts >::Variant ( const Variant< Ts > & other)
constexprdefault

copy constructor.

Parameters
otherobject to copy.

◆ Variant() [3/10]

template<typename... Ts>
join::Variant< Ts >::Variant ( const Variant< Ts > & other)
inlineconstexpr

copy constructor.

Parameters
otherobject to copy.

◆ Variant() [4/10]

template<typename... Ts>
join::Variant< Ts >::Variant ( Variant< Ts > && other)
constexprdefault

move constructor.

Parameters
otherobject to move.

◆ Variant() [5/10]

template<typename... Ts>
join::Variant< Ts >::Variant ( Variant< Ts > && other)
inlineconstexprnoexcept

move constructor.

Parameters
otherobject to move.

◆ Variant() [6/10]

template<typename... Ts>
template<typename T , typename Match = match_t<T&&, Ts...>>
requires is_unique_v<Match, Ts...> && std::is_constructible_v<Match, T&&>
join::Variant< Ts >::Variant ( T && t)
inlineconstexpr

constructs a Variant holding the alternative selected by overload resolution.

Parameters
tValue convertible to one of the variant's alternatives

◆ Variant() [7/10]

template<typename... Ts>
template<typename T , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, Args&&...>
join::Variant< Ts >::Variant ( std::in_place_type_t< T > ,
Args &&... args )
inlineexplicitconstexpr

constructs a Variant with the specified alternative T.

Parameters
argsarguments to initialize the contained value with.

◆ Variant() [8/10]

template<typename... Ts>
template<typename T , typename Up , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, std::initializer_list<Up>&, Args&&...>
join::Variant< Ts >::Variant ( std::in_place_type_t< T > ,
std::initializer_list< Up > il,
Args &&... args )
inlineexplicitconstexpr

constructs a Variant with the specified alternative T.

Parameters
argsarguments to initialize the contained value with.

◆ Variant() [9/10]

template<typename... Ts>
template<std::size_t I, typename... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, Args&&...>
join::Variant< Ts >::Variant ( std::in_place_index_t< I > ,
Args &&... args )
inlineexplicitconstexpr

constructs a variant with the alternative T specified by the index I.

Parameters
argsarguments to initialize the contained value with.

◆ Variant() [10/10]

template<typename... Ts>
template<std::size_t I, typename Up , typename... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, std::initializer_list<Up>&, Args&&...>
join::Variant< Ts >::Variant ( std::in_place_index_t< I > ,
std::initializer_list< Up > il,
Args &&... args )
inlineexplicitconstexpr

constructs a variant with the alternative T specified by the index I.

Parameters
argsarguments to initialize the contained value with.

◆ ~Variant() [1/2]

template<typename... Ts>
join::Variant< Ts >::~Variant ( )
default

destroy the Variant instance.

◆ ~Variant() [2/2]

template<typename... Ts>
join::Variant< Ts >::~Variant ( )
inline

destroy the Variant instance.

Member Function Documentation

◆ compare()

template<typename... Ts>
auto join::Variant< Ts >::compare ( const Variant< Ts > & rhs) const
inlineconstexprprotected

three-way compare.

Parameters
rhsvalue to compare to.
Returns
ordering of this relative to rhs.

◆ equal()

template<typename... Ts>
bool join::Variant< Ts >::equal ( const Variant< Ts > & rhs) const
inlineconstexprprotected

check if equal.

Parameters
rhsvalue to compare to.
Returns
true if equal, false otherwise.

◆ get() [1/4]

template<typename... Ts>
template<typename T >
requires is_unique_v<T, Ts...>
T & join::Variant< Ts >::get ( )
inlineconstexpr

get the variable value of the object type identified by type.

Returns
the object value.

◆ get() [2/4]

template<typename... Ts>
template<std::size_t I>
requires (I < sizeof...(Ts))
std::tuple_element_t< I, std::tuple< Ts... > > & join::Variant< Ts >::get ( )
inlineconstexpr

get the variable value of the object type identified by index.

Returns
the object value.

◆ get() [3/4]

template<typename... Ts>
template<typename T >
requires is_unique_v<T, Ts...>
const T & join::Variant< Ts >::get ( ) const
inlineconstexpr

get the variable value of the object type identified by type.

Returns
the object value.

◆ get() [4/4]

template<typename... Ts>
template<std::size_t I>
requires (I < sizeof...(Ts))
const std::tuple_element_t< I, std::tuple< Ts... > > & join::Variant< Ts >::get ( ) const
inlineconstexpr

get the variable value of the object type identified by index.

Returns
the object value.

◆ getIf() [1/4]

template<typename... Ts>
template<typename T >
requires is_unique_v<T, Ts...>
T * join::Variant< Ts >::getIf ( )
inlineconstexpr

get the variable value address of the object type identified by type.

Returns
the object value address if type is correct, nullptr otherwise.

◆ getIf() [2/4]

template<typename... Ts>
template<std::size_t I>
requires (I < sizeof...(Ts))
std::tuple_element_t< I, std::tuple< Ts... > > * join::Variant< Ts >::getIf ( )
inlineconstexpr

get the variable value address of the object type identified by index.

Returns
the object value address if index is correct, nullptr otherwise.

◆ getIf() [3/4]

template<typename... Ts>
template<typename T >
requires is_unique_v<T, Ts...>
const T * join::Variant< Ts >::getIf ( ) const
inlineconstexpr

get the variable value address of the object type identified by type.

Returns
the object value address if type is correct, nullptr otherwise.

◆ getIf() [4/4]

template<typename... Ts>
template<std::size_t I>
requires (I < sizeof...(Ts))
const std::tuple_element_t< I, std::tuple< Ts... > > * join::Variant< Ts >::getIf ( ) const
inlineconstexpr

get the variable value address of the object type identified by index.

Returns
the object value address if index is correct, nullptr otherwise.

◆ index()

template<typename... Ts>
std::size_t join::Variant< Ts >::index ( ) const
inlineconstexprnoexcept

return the index of the alternative that is currently held by the variant.

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

◆ is() [1/2]

template<typename... Ts>
template<typename T >
requires is_unique_v<T, Ts...>
bool join::Variant< Ts >::is ( ) const
inlineconstexpr

check that the member type in use is the same than the one specified.

Returns
true if the type is the same, false otherwise.

◆ is() [2/2]

template<typename... Ts>
template<std::size_t I>
requires (I < sizeof...(Ts))
bool join::Variant< Ts >::is ( ) const
inlineconstexpr

check that the index in use is the same than the one specified.

Returns
true if the index is the same, false otherwise.

◆ operator=() [1/5]

template<typename... Ts>
Variant & join::Variant< Ts >::operator= ( const Variant< Ts > & other)
inlineconstexpr

copy assignment.

Parameters
otherobject to copy.
Returns
a reference of the current object.

◆ operator=() [2/5]

template<typename... Ts>
Variant & join::Variant< Ts >::operator= ( const Variant< Ts > & other)
constexprdefault

copy assignment.

Parameters
otherobject to copy.
Returns
a reference of the current object.

◆ operator=() [3/5]

template<typename... Ts>
template<typename T , typename Match = match_t<T&&, Ts...>>
requires is_unique_v<Match, Ts...> && std::is_constructible_v<Match, T&&>
Variant & join::Variant< Ts >::operator= ( T && t)
inlineconstexpr

assign a Variant holding the alternative selected by overload resolution.

Parameters
tValue convertible to one of the variant's alternatives
Returns
a reference of the current object.

◆ operator=() [4/5]

template<typename... Ts>
Variant & join::Variant< Ts >::operator= ( Variant< Ts > && other)
inlineconstexprnoexcept

move assignment.

Parameters
otherobject to move.
Returns
a reference of the current object.

◆ operator=() [5/5]

template<typename... Ts>
Variant & join::Variant< Ts >::operator= ( Variant< Ts > && other)
constexprdefault

move assignment.

Parameters
otherobject to move.
Returns
a reference of the current object.

◆ set() [1/4]

template<typename... Ts>
template<typename T , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, Args&&...>
T & join::Variant< Ts >::set ( Args &&... args)
inlineconstexpr

set the variable type of the object identified by type and assign it a value.

Parameters
argsargument(s) to set.

◆ set() [2/4]

template<typename... Ts>
template<std::size_t I, typename... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, Args&&...>
std::tuple_element_t< I, std::tuple< Ts... > > & join::Variant< Ts >::set ( Args &&... args)
inlineconstexpr

set the variable type of the object identified by index and assign it a value.

Parameters
argsargument(s) to set.

◆ set() [3/4]

template<typename... Ts>
template<typename T , typename Up , typename... Args>
requires is_unique_v<T, Ts...> && std::is_constructible_v<T, std::initializer_list<Up>&, Args&&...>
T & join::Variant< Ts >::set ( std::initializer_list< Up > il,
Args &&... args )
inlineconstexpr

set the variable type of the object identified by type and assign it a value.

Parameters
argsargument(s) to set.

◆ set() [4/4]

template<typename... Ts>
template<std::size_t I, class Up , class... Args>
requires std::is_constructible_v<std::tuple_element_t<I, std::tuple<Ts...>>, std::initializer_list<Up>&, Args&&...>
std::tuple_element_t< I, std::tuple< Ts... > > & join::Variant< Ts >::set ( std::initializer_list< Up > il,
Args &&... args )
inlineconstexpr

set the variable type of the object identified by index and assign it a value.

Parameters
argsargument(s) to set.

◆ swap()

template<typename... Ts>
void join::Variant< Ts >::swap ( Variant< Ts > & other)
inlinenoexcept

swap this variant with another.

Parameters
othervariant to swap with.

Friends And Related Symbol Documentation

◆ operator<=>

template<typename... Ts>
template<typename... _Ts>
details::VariantOrdering< _Ts... > operator<=> ( const Variant< _Ts... > & lhs,
const Variant< _Ts... > & rhs )
friend

◆ operator==

template<typename... Ts>
template<typename... _Ts>
bool operator== ( const Variant< _Ts... > & lhs,
const Variant< _Ts... > & rhs )
friend

The documentation for this class was generated from the following file: