Backport
variant.hpp File Reference

This header provides definitions from the C++ header <variant> More...

#include "detail/config.hpp"
#include "detail/enable_overload.hpp"
#include "detail/nth_type.hpp"
#include "detail/variant_base.hpp"
#include "detail/variant_visitors.hpp"
#include "detail/variant_traits.hpp"
#include "tuple.hpp"
#include "utility.hpp"
#include "type_traits.hpp"
#include "functional.hpp"
#include <initializer_list>
#include <memory>
#include <exception>
#include <cstddef>
#include <utility>
+ Include dependency graph for variant.hpp:

Go to the source code of this file.

Classes

struct  bpstd::monostate
 
class  bpstd::variant< Types >
 The class template variant represents a type-safe union. More...
 
struct  bpstd::variant_size< T >
 Provides access to the number of alternatives in a possibly cv-qualified variant as a compile-time constant expression. More...
 
struct  bpstd::variant_size< const T >
 
struct  bpstd::variant_size< volatile T >
 
struct  bpstd::variant_size< const volatile T >
 
struct  bpstd::variant_size< variant< Types... > >
 
struct  bpstd::variant_alternative< I, T >
 Helper variable template for extracting variant_size<T>::value. More...
 
struct  bpstd::variant_alternative< I, const T >
 
struct  bpstd::variant_alternative< I, volatile T >
 
struct  bpstd::variant_alternative< I, const volatile T >
 
struct  bpstd::variant_alternative< I, variant< Types... > >
 
class  bpstd::bad_variant_access
 Exception thrown by variant. More...
 
class  bpstd::variant< Types >
 The class template variant represents a type-safe union. More...
 

Typedefs

template<std::size_t I, typename T >
using bpstd::variant_alternative_t = typename variant_alternative< I, T >::type
 A helper template for extracting the ::type from variant_alternative. More...
 
template<typename T , typename... Types>
using bpstd::detail::constructible_alternative_t = typename constructible_alternative< T, Types... >::type
 
template<typename T , typename... Types>
using bpstd::detail::can_construct_alternative = can_construct_alternative_impl< has_constructible_alternative< T, Types... >::value, T, Types... >
 
template<typename T , typename... Types>
using bpstd::detail::can_assign_alternative = can_assign_alternative_impl< has_constructible_alternative< T, Types... >::value, T, Types... >
 

Functions

constexpr bool bpstd::operator== (monostate, monostate) noexcept
 
constexpr bool bpstd::operator!= (monostate, monostate) noexcept
 
constexpr bool bpstd::operator< (monostate, monostate) noexcept
 
constexpr bool bpstd::operator> (monostate, monostate) noexcept
 
constexpr bool bpstd::operator<= (monostate, monostate) noexcept
 
constexpr bool bpstd::operator>= (monostate, monostate) noexcept
 
template<typename... Types>
BPSTD_CPP14_CONSTEXPR bool bpstd::operator== (const variant< Types... > &lhs, const variant< Types... > &rhs) noexcept
 
template<typename... Types>
BPSTD_CPP14_CONSTEXPR bool bpstd::operator!= (const variant< Types... > &lhs, const variant< Types... > &rhs) noexcept
 
template<typename... Types>
BPSTD_CPP14_CONSTEXPR bool bpstd::operator< (const variant< Types... > &lhs, const variant< Types... > &rhs) noexcept
 
template<typename... Types>
BPSTD_CPP14_CONSTEXPR bool bpstd::operator> (const variant< Types... > &lhs, const variant< Types... > &rhs) noexcept
 
template<typename... Types>
BPSTD_CPP14_CONSTEXPR bool bpstd::operator<= (const variant< Types... > &lhs, const variant< Types... > &rhs) noexcept
 
template<typename... Types>
BPSTD_CPP14_CONSTEXPR bool bpstd::operator>= (const variant< Types... > &lhs, const variant< Types... > &rhs) noexcept
 
template<typename... Types>
void bpstd::swap (variant< Types... > &lhs, variant< Types... > &rhs) noexcept(noexcept(lhs.swap(rhs)))
 Swaps the contents of lhs with rhs. More...
 
template<typename Visitor , typename Variant >
BPSTD_CPP14_CONSTEXPR bpstd::detail::variant_visitor_invoke_result_t< Visitor, Variant > bpstd::visit (Visitor &&visitor, Variant &&v)
 Visits the variant v with the given visitor. More...
 
template<typename Visitor , typename Variant0 , typename... Variants>
BPSTD_CPP14_CONSTEXPR bpstd::detail::variant_visitor_invoke_result_t< Visitor, Variant0, Variants... > bpstd::visit (Visitor &&visitor, Variant0 &&variant0, Variants &&...variants)
 
template<typename T , typename... Types>
constexpr bool bpstd::holds_alternative (const variant< Types... > &v) noexcept
 Checks if the variant v holds the alternative T. More...
 
template<typename Variant0 , typename... Variants>
constexpr BPSTD_INLINE_VISIBILITY bool bpstd::detail::are_any_valueless_by_exception (const Variant0 &v0, const Variants &...vs)
 
template<typename Variant0 >
constexpr BPSTD_INLINE_VISIBILITY bool bpstd::detail::are_any_valueless_by_exception (const Variant0 &v0)
 
template<typename... Args, typename T , std::size_t... Idxs>
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR std::tuple< Args &&..., T && > bpstd::detail::tuple_push_back_aux (std::tuple< Args... > &args, T &&v, index_sequence< Idxs... >)
 
template<typename... Args, typename T >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR std::tuple< Args &&..., T && > bpstd::detail::tuple_push_back (std::tuple< Args... > &args, T &&t)
 
template<typename Arg0 , typename... Args, std::size_t... Idxs>
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR std::tuple< Args... > bpstd::detail::tuple_pop_front_aux (std::tuple< Arg0, Args... > &args, index_sequence< 0, Idxs... >)
 
template<typename Arg0 , typename... Args>
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR std::tuple< Args... > bpstd::detail::tuple_pop_front (std::tuple< Arg0, Args... > &args)
 
template<typename T , typename Visitor , typename Variants , typename Arguments >
BPSTD_CPP14_CONSTEXPR multi_variant_visitor< T, Visitor, remove_cvref_t< Variants >, remove_cvref_t< Arguments > > bpstd::detail::make_multi_visitor (Visitor &&vistior, Variants &&variants, Arguments &&args)
 
template<typename T , typename Visitor , typename Variants , typename Arguments >
BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR multi_variant_visitor< T, Visitor, remove_cvref_t< Variants >, remove_cvref_t< Arguments > > bpstd::detail::make_multi_visitor (Visitor &&visitor, Variants &&variants, Arguments &&args)
 
template<std::size_t I, typename... Types>
BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > & bpstd::get (variant< Types... > &v)
 Gets the alternative at index I from the variant v. More...
 
template<std::size_t I, typename... Types>
BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > && bpstd::get (variant< Types... > &&v)
 Gets the alternative at index I from the variant v. More...
 
template<std::size_t I, typename... Types>
const BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > & bpstd::get (const variant< Types... > &v)
 Gets the alternative at index I from the variant v. More...
 
template<std::size_t I, typename... Types>
const BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > && bpstd::get (const variant< Types... > &&v)
 Gets the alternative at index I from the variant v. More...
 
template<typename T , typename... Types>
BPSTD_CPP14_CONSTEXPR T & bpstd::get (variant< Types... > &v)
 Gets the underlying element of the variant with the specified type. More...
 
template<typename T , typename... Types>
BPSTD_CPP14_CONSTEXPR T && bpstd::get (variant< Types... > &&v)
 Gets the underlying element of the variant with the specified type. More...
 
template<typename T , typename... Types>
const BPSTD_CPP14_CONSTEXPR T & bpstd::get (const variant< Types... > &v)
 Gets the underlying element of the variant with the specified type. More...
 
template<typename T , typename... Types>
const BPSTD_CPP14_CONSTEXPR T && bpstd::get (const variant< Types... > &&v)
 Gets the underlying element of the variant with the specified type. More...
 
template<std::size_t I, typename... Types>
constexpr add_pointer_t< variant_alternative_t< I, variant< Types... > > > bpstd::get_if (variant< Types... > *pv) noexcept
 Index-based non-throwing accessor. More...
 
template<std::size_t I, typename... Types>
constexpr add_pointer_t< const variant_alternative_t< I, variant< Types... > > > bpstd::get_if (const variant< Types... > *pv) noexcept
 Index-based non-throwing accessor. More...
 
template<typename T , typename... Types>
constexpr add_pointer_t< T > bpstd::get_if (variant< Types... > *pv) noexcept
 Type-based non-throwing accessor. More...
 
template<typename T , typename... Types>
constexpr add_pointer_t< const T > bpstd::get_if (const variant< Types... > *pv) noexcept
 Type-based non-throwing accessor. More...
 
template<std::size_t I, typename... Types>
BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > & bpstd::get (variant< Types... > &v)
 Gets the alternative at index I from the variant v. More...
 
template<std::size_t I, typename... Types>
BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > && bpstd::get (variant< Types... > &&v)
 Gets the alternative at index I from the variant v. More...
 
template<std::size_t I, typename... Types>
const BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > & bpstd::get (const variant< Types... > &v)
 Gets the alternative at index I from the variant v. More...
 
template<std::size_t I, typename... Types>
const BPSTD_CPP14_CONSTEXPR variant_alternative_t< I, variant< Types... > > && bpstd::get (const variant< Types... > &&v)
 Gets the alternative at index I from the variant v. More...
 
template<typename T , typename... Types>
BPSTD_CPP14_CONSTEXPR T & bpstd::get (variant< Types... > &v)
 Gets the underlying element of the variant with the specified type. More...
 
template<typename T , typename... Types>
BPSTD_CPP14_CONSTEXPR T && bpstd::get (variant< Types... > &&v)
 Gets the underlying element of the variant with the specified type. More...
 
template<typename T , typename... Types>
const BPSTD_CPP14_CONSTEXPR T & bpstd::get (const variant< Types... > &v)
 Gets the underlying element of the variant with the specified type. More...
 
template<typename T , typename... Types>
const BPSTD_CPP14_CONSTEXPR T && bpstd::get (const variant< Types... > &&v)
 Gets the underlying element of the variant with the specified type. More...
 
template<std::size_t I, typename... Types>
constexpr add_pointer_t< variant_alternative_t< I, variant< Types... > > > bpstd::get_if (variant< Types... > *pv) noexcept
 Index-based non-throwing accessor. More...
 
template<std::size_t I, typename... Types>
constexpr add_pointer_t< const variant_alternative_t< I, variant< Types... > > > bpstd::get_if (const variant< Types... > *pv) noexcept
 Index-based non-throwing accessor. More...
 
template<typename T , typename... Types>
constexpr add_pointer_t< T > bpstd::get_if (variant< Types... > *pv) noexcept
 Type-based non-throwing accessor. More...
 
template<typename T , typename... Types>
constexpr add_pointer_t< const T > bpstd::get_if (const variant< Types... > *pv) noexcept
 Type-based non-throwing accessor. More...
 

Variables

constexpr BPSTD_CPP17_INLINE auto bpstd::variant_npos = static_cast<std::size_t>(-1)
 This is a special value equal to the largest value representable by the type std::size_t, used as the return type of index() when valueless_by_exception() is true.
 

Detailed Description

This header provides definitions from the C++ header <variant>

Definition in file variant.hpp.

Typedef Documentation

◆ variant_alternative_t

template<std::size_t I, typename T >
using bpstd::variant_alternative_t = typedef typename variant_alternative<I, T>::type

A helper template for extracting the ::type from variant_alternative.

Template Parameters
Ithe index
Tthe variant

Definition at line 155 of file variant.hpp.

Function Documentation

◆ get() [1/8]

template<std::size_t I, typename... Types>
const BPSTD_CPP14_CONSTEXPR variant_alternative_t<I, variant<Types...> >&& bpstd::get ( const variant< Types... > &&  v)

Gets the alternative at index I from the variant v.

Template Parameters
Ithe alternative index
Parameters
vthe variant
Returns
the alternative at index I

◆ get() [2/8]

template<typename T , typename... Types>
const BPSTD_CPP14_CONSTEXPR T&& bpstd::get ( const variant< Types... > &&  v)

Gets the underlying element of the variant with the specified type.

Exceptions
bad_variant_accessif T is not the active alternative
Template Parameters
Tthe type of the alternative to retrieve
Parameters
vthe variant to extract the entry from
Returns
the alternative

◆ get() [3/8]

template<std::size_t I, typename... Types>
const BPSTD_CPP14_CONSTEXPR variant_alternative_t<I, variant<Types...> >& bpstd::get ( const variant< Types... > &  v)

Gets the alternative at index I from the variant v.

Template Parameters
Ithe alternative index
Parameters
vthe variant
Returns
the alternative at index I

◆ get() [4/8]

template<typename T , typename... Types>
const BPSTD_CPP14_CONSTEXPR T& bpstd::get ( const variant< Types... > &  v)

Gets the underlying element of the variant with the specified type.

Exceptions
bad_variant_accessif T is not the active alternative
Template Parameters
Tthe type of the alternative to retrieve
Parameters
vthe variant to extract the entry from
Returns
the alternative

◆ get() [5/8]

template<std::size_t I, typename... Types>
BPSTD_CPP14_CONSTEXPR variant_alternative_t<I, variant<Types...> >&& bpstd::get ( variant< Types... > &&  v)

Gets the alternative at index I from the variant v.

Template Parameters
Ithe alternative index
Parameters
vthe variant
Returns
the alternative at index I

◆ get() [6/8]

template<typename T , typename... Types>
BPSTD_CPP14_CONSTEXPR T&& bpstd::get ( variant< Types... > &&  v)

Gets the underlying element of the variant with the specified type.

Exceptions
bad_variant_accessif T is not the active alternative
Template Parameters
Tthe type of the alternative to retrieve
Parameters
vthe variant to extract the entry from
Returns
the alternative

◆ get() [7/8]

template<std::size_t I, typename... Types>
BPSTD_CPP14_CONSTEXPR variant_alternative_t<I, variant<Types...> >& bpstd::get ( variant< Types... > &  v)

Gets the alternative at index I from the variant v.

Template Parameters
Ithe alternative index
Parameters
vthe variant
Returns
the alternative at index I

◆ get() [8/8]

template<typename T , typename... Types>
BPSTD_CPP14_CONSTEXPR T& bpstd::get ( variant< Types... > &  v)

Gets the underlying element of the variant with the specified type.

Exceptions
bad_variant_accessif T is not the active alternative
Template Parameters
Tthe type of the alternative to retrieve
Parameters
vthe variant to extract the entry from
Returns
the alternative

◆ get_if() [1/4]

template<std::size_t I, typename... Types>
constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...> > > bpstd::get_if ( const variant< Types... > *  pv)
constexprnoexcept

Index-based non-throwing accessor.

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 Parameters
Ithe index of the alternative to extract
Parameters
pvthe pointer to the variant to extract the value from
Returns
pointer to the variant alternative when successful

◆ get_if() [2/4]

template<typename T , typename... Types>
constexpr add_pointer_t<const T> bpstd::get_if ( const variant< Types... > *  pv)
constexprnoexcept

Type-based non-throwing accessor.

Equivalent to the index-based get_if with I being the zero-based index of T in Types....

The call is ill-formed if T is not a unique element of Types.

Template Parameters
Tthe alternative type to retrieve
Parameters
pvthe pointer to the variant to extract the value from
Returns
pointer to the variant alternative when successful

◆ get_if() [3/4]

template<std::size_t I, typename... Types>
constexpr add_pointer_t<variant_alternative_t<I, variant<Types...> > > bpstd::get_if ( variant< Types... > *  pv)
constexprnoexcept

Index-based non-throwing accessor.

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 Parameters
Ithe index of the alternative to extract
Parameters
pvthe pointer to the variant to extract the value from
Returns
pointer to the variant alternative when successful

◆ get_if() [4/4]

template<typename T , typename... Types>
constexpr add_pointer_t<T> bpstd::get_if ( variant< Types... > *  pv)
constexprnoexcept

Type-based non-throwing accessor.

Equivalent to the index-based get_if with I being the zero-based index of T in Types....

The call is ill-formed if T is not a unique element of Types.

Template Parameters
Tthe alternative type to retrieve
Parameters
pvthe pointer to the variant to extract the value from
Returns
pointer to the variant alternative when successful

◆ holds_alternative()

template<typename T , typename... Types>
constexpr bool bpstd::holds_alternative ( const variant< Types... > &  v)
constexprnoexcept

Checks if the variant v holds the alternative T.

The call is ill-formed if T appears more than once in Types...

Parameters
vvariant to examine
Returns
true if the variant currently holds the alternative T

◆ swap()

template<typename... Types>
void bpstd::swap ( variant< Types... > &  lhs,
variant< Types... > &  rhs 
)
noexcept

Swaps the contents of lhs with rhs.

Parameters
lhsthe left contents to swap
rhsthe right contents to swap

◆ visit()

template<typename Visitor , typename Variant >
BPSTD_CPP14_CONSTEXPR bpstd::detail::variant_visitor_invoke_result_t<Visitor,Variant> bpstd::visit ( Visitor &&  visitor,
Variant &&  v 
)

Visits the variant v with the given visitor.

Parameters
visitorthe visitor to visit the active entry of v
vthe variant to visit
Returns
the result of visiting the variant v