Audacity 3.2.0
Classes | Typedefs | Functions
Variant::detail Namespace Reference

Classes

struct  type_identity
 Standard in C++20. More...
 
struct  VisitHelperReturn
 Help to define Visit() below. More...
 

Typedefs

template<typename T >
using deduced_variant = typename decltype(deduce_variant(std::declval< T >()))::type
 

Functions

template<typename Visitor , typename Variant >
auto VisitHelperBad (Visitor &&, Variant &&) -> typename VisitHelperReturn< Visitor &&, Variant && >::type
 Help to define Visit() below. More...
 
template<size_t Index, typename Visitor , typename Variant >
decltype(auto) VisitHelperFunction (Visitor &&vis, Variant &&var)
 Help to define Visit() below. More...
 
template<size_t Index, typename Visitor , typename Variant >
auto TypeCheckedVisitHelperFunction (Visitor &&vis, Variant &&var) -> typename VisitHelperReturn< Visitor &&, Variant && >::type
 Help to define Visit() below. More...
 
template<size_t... Indices, typename Visitor , typename Variant >
decltype(auto) VisitHelper (std::index_sequence< Indices... >, Visitor &&vis, Variant &&var)
 Help to define Visit() below. More...
 
auto deduce_variant (...) -> void
 Unevaluated. More...
 
template<typename... Types>
auto deduce_variant (std::variant< Types... > &v) -> type_identity< std::remove_reference_t< decltype(v)> >
 
template<typename... Types>
auto deduce_variant (std::variant< Types... > &&v) -> type_identity< std::remove_reference_t< decltype(v)> >
 
template<typename... Types>
auto deduce_variant (const std::variant< Types... > &v) -> type_identity< std::remove_reference_t< decltype(v)> >
 
template<typename... Types>
auto deduce_variant (const std::variant< Types... > &&v) -> type_identity< std::remove_reference_t< decltype(v)> >
 
template<typename ForwardType , typename Variant >
decltype(auto) forward_variant (Variant &var)
 
template<typename ForwardType , typename Variant >
decltype(auto) forward_variant (const Variant &var)
 

Typedef Documentation

◆ deduced_variant

template<typename T >
using Variant::detail::deduced_variant = typedef typename decltype(deduce_variant(std::declval<T>()))::type

Definition at line 116 of file Variant.h.

Function Documentation

◆ deduce_variant() [1/5]

auto Variant::detail::deduce_variant (   ...) -> void

Unevaluated.

◆ deduce_variant() [2/5]

template<typename... Types>
auto Variant::detail::deduce_variant ( const std::variant< Types... > &&  v) -> type_identity< std::remove_reference_t< decltype(v)> >

◆ deduce_variant() [3/5]

template<typename... Types>
auto Variant::detail::deduce_variant ( const std::variant< Types... > &  v) -> type_identity< std::remove_reference_t< decltype(v)> >

◆ deduce_variant() [4/5]

template<typename... Types>
auto Variant::detail::deduce_variant ( std::variant< Types... > &&  v) -> type_identity< std::remove_reference_t< decltype(v)> >

◆ deduce_variant() [5/5]

template<typename... Types>
auto Variant::detail::deduce_variant ( std::variant< Types... > &  v) -> type_identity< std::remove_reference_t< decltype(v)> >

◆ forward_variant() [1/2]

template<typename ForwardType , typename Variant >
decltype(auto) Variant::detail::forward_variant ( const Variant &  var)

Definition at line 125 of file Variant.h.

125 {
126 return std::forward<ForwardType>(var);
127}

◆ forward_variant() [2/2]

template<typename ForwardType , typename Variant >
decltype(auto) Variant::detail::forward_variant ( Variant &  var)

Definition at line 120 of file Variant.h.

120 {
121 return std::forward<ForwardType>(var);
122
123}

◆ TypeCheckedVisitHelperFunction()

template<size_t Index, typename Visitor , typename Variant >
auto Variant::detail::TypeCheckedVisitHelperFunction ( Visitor &&  vis,
Variant &&  var 
) -> typename VisitHelperReturn<Visitor&&, Variant&&>::type

Help to define Visit() below.

Definition at line 68 of file Variant.h.

70{
71 static_assert(std::is_same_v<
73 std::invoke_result_t<
74 decltype(VisitHelperFunction<Index, Visitor&&, Variant&&>),
75 Visitor &&, Variant &&>
76 >,
77 "Visitor must return the same type for all alternatives of the Variant.");
78 return VisitHelperFunction<Index>(
79 std::forward<Visitor>(vis), std::forward<Variant>(var));
80}
decltype(std::invoke(std::declval< Visitor && >(), std::declval< Arg >())) type
Definition: Variant.h:39

◆ VisitHelper()

template<size_t... Indices, typename Visitor , typename Variant >
decltype(auto) Variant::detail::VisitHelper ( std::index_sequence< Indices... >  ,
Visitor &&  vis,
Variant &&  var 
)

Help to define Visit() below.

Definition at line 85 of file Variant.h.

86{
87 constexpr auto size = sizeof...(Indices);
89 using Function = Return(*)(Visitor&&, Variant&&);
90 static constexpr std::array<Function, size + 1> jumpTable{
91 TypeCheckedVisitHelperFunction<Indices>...,
93 };
94 auto function = jumpTable[std::min(var.index(), size)];
95 return function(std::forward<Visitor>(vis), std::forward<Variant>(var));
96}
int min(int a, int b)
auto VisitHelperBad(Visitor &&, Variant &&) -> typename VisitHelperReturn< Visitor &&, Variant && >::type
Help to define Visit() below.
Definition: Variant.h:44

References min(), size, and VisitHelperBad().

Referenced by Variant::Visit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VisitHelperBad()

template<typename Visitor , typename Variant >
auto Variant::detail::VisitHelperBad ( Visitor &&  ,
Variant &&   
) -> typename VisitHelperReturn<Visitor&&, Variant&&>::type

Help to define Visit() below.

Definition at line 44 of file Variant.h.

46{
47 // Fall through here when the variant holds no value
48 // Should really throw std::bad_variant_access but that may not be available
49 throw std::invalid_argument{"Bad variant"};
50}

Referenced by VisitHelper().

Here is the caller graph for this function:

◆ VisitHelperFunction()

template<size_t Index, typename Visitor , typename Variant >
decltype(auto) Variant::detail::VisitHelperFunction ( Visitor &&  vis,
Variant &&  var 
)

Help to define Visit() below.

Definition at line 54 of file Variant.h.

55{
56 // Invoke vis at most once
57 const auto pValue = std::get_if<Index>(&var);
58 // Trust VisitHelper to dispatch correctly
59 assert(pValue);
60 if constexpr (std::is_lvalue_reference_v<Variant>)
61 return std::invoke(std::forward<Visitor>(vis), (*pValue));
62 else
63 return std::invoke(std::forward<Visitor>(vis), std::move(*pValue));
64}