Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Tester< Const, ref > Struct Template Reference

Parameterize for the type of visitor return. More...

Classes

struct  CopyOnly
 
struct  X
 
struct  Y
 Structure can specialize with only a non-const member function. More...
 
struct  Z
 Structure always with a const member function. More...
 

Public Types

template<typename T >
using MaybeConst = std::conditional_t< Const, const T, T >
 
using ResultType = std::conditional_t< ref==noref, MaybeConst< ValueType >, std::conditional_t< ref==rvalue, std::add_rvalue_reference_t< MaybeConst< ValueType > >, std::add_lvalue_reference_t< MaybeConst< ValueType > > > >
 
using VariantType = std::conditional_t< ref==lvalue, std::variant< MaybeConst< X >, MaybeConst< Y >, MaybeConst< Z >, MaybeConst< float >, MaybeConst< double >, MaybeConst< long double > >, std::variant< MaybeConst< Y >, MaybeConst< Z >, MaybeConst< float >, MaybeConst< double >, MaybeConst< long double > > >
 

Public Member Functions

void DoTests ()
 

Static Public Member Functions

template<int Value>
static ResultType value ()
 
static ResultType nakedFunction (float)
 
static auto moveOnly ()
 
template<typename Visitor , typename Arg >
static void testCase (const Visitor &visitor, int result, Arg &arg)
 

Detailed Description

template<bool Const, Ref ref = lvalue>
struct Tester< Const, ref >

Parameterize for the type of visitor return.

Definition at line 29 of file VariantTest.cpp.

Member Typedef Documentation

◆ MaybeConst

template<bool Const, Ref ref = lvalue>
template<typename T >
using Tester< Const, ref >::MaybeConst = std::conditional_t<Const, const T, T>

Definition at line 32 of file VariantTest.cpp.

◆ ResultType

template<bool Const, Ref ref = lvalue>
using Tester< Const, ref >::ResultType = std::conditional_t<ref == noref, MaybeConst<ValueType>, std::conditional_t<ref == rvalue, std::add_rvalue_reference_t<MaybeConst<ValueType> >, std::add_lvalue_reference_t<MaybeConst<ValueType> > > >

Definition at line 34 of file VariantTest.cpp.

◆ VariantType

template<bool Const, Ref ref = lvalue>
using Tester< Const, ref >::VariantType = std::conditional_t<ref == lvalue, std::variant< MaybeConst<X>, MaybeConst<Y>, MaybeConst<Z>, MaybeConst<float>, MaybeConst<double>, MaybeConst<long double> >, std::variant< MaybeConst<Y>, MaybeConst<Z>, MaybeConst<float>, MaybeConst<double>, MaybeConst<long double> > >

Definition at line 88 of file VariantTest.cpp.

Member Function Documentation

◆ DoTests()

template<bool Const, Ref ref = lvalue>
void Tester< Const, ref >::DoTests ( )
inline

Definition at line 133 of file VariantTest.cpp.

134{
135 // Callable::OverloadSet can capture many kinds of things. Test each.
136 // This also tests compilation of the variadic constructor of OverloadSet
137 // which can take a mix of l- and rvalues.
138 CopyOnly copyOnly;
139 const auto visitor = Callable::OverloadSet(
140 &X::member,
141 &Y::template memberfunction<Const>,
144 moveOnly(),
145 copyOnly
146 );
147
148 X x;
149 Y y;
150 Z z;
151 float f{};
152 double d{};
153 long double ld{};
154
155 // Pointer to data member, captured as INVOKE-able, can only return lvalue
156 // references, so it is excluded from other test cases
157 if constexpr (ref == lvalue)
158 testCase(visitor, 0, x);
159
160 testCase(visitor, 1, y);
161 testCase(visitor, 2, z);
162 testCase(visitor, 3, f);
163 testCase(visitor, 4, d);
164 testCase(visitor, 5, ld);
165
166 // An invocable can distinguish its own value category and constness
167 REQUIRE(6 == std::move(visitor)(ld));
168 using ConstVisitorType = decltype(visitor);
169 using VisitorType = std::remove_const_t<ConstVisitorType>;
170 auto &mutVisitor = const_cast<VisitorType&>(visitor);
171 REQUIRE(7 == mutVisitor(ld));
172 REQUIRE(8 == std::move(mutVisitor)(ld));
173}
@ lvalue
Definition: VariantTest.cpp:17
OverloadSet(Is &&... invocables) -> OverloadSet< Is &&... >
ValueType member
Definition: VariantTest.cpp:52
ResultType constmemberfunction() const
Definition: VariantTest.cpp:63
static ResultType nakedFunction(float)
Definition: VariantTest.cpp:65
static void testCase(const Visitor &visitor, int result, Arg &arg)
static auto moveOnly()
Definition: VariantTest.cpp:66

References Tester< Const, ref >::Z::constmemberfunction(), lvalue, Tester< Const, ref >::X::member, Tester< Const, ref >::moveOnly(), Tester< Const, ref >::nakedFunction(), Callable::OverloadSet(), and Tester< Const, ref >::testCase().

Referenced by TEST_CASE().

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

◆ moveOnly()

template<bool Const, Ref ref = lvalue>
static auto Tester< Const, ref >::moveOnly ( )
inlinestatic

Definition at line 66 of file VariantTest.cpp.

66 {
67 // Note: remove trailing return type and compilation of Visit correctly
68 // breaks because a value, not reference results for one alternative
69 return [u = std::make_unique<X>()](double) -> ResultType
70 { return value<4>(); };
71}
std::conditional_t< ref==noref, MaybeConst< ValueType >, std::conditional_t< ref==rvalue, std::add_rvalue_reference_t< MaybeConst< ValueType > >, std::add_lvalue_reference_t< MaybeConst< ValueType > > > > ResultType
Definition: VariantTest.cpp:40

Referenced by Tester< Const, ref >::DoTests().

Here is the caller graph for this function:

◆ nakedFunction()

template<bool Const, Ref ref = lvalue>
static ResultType Tester< Const, ref >::nakedFunction ( float  )
inlinestatic

Definition at line 65 of file VariantTest.cpp.

65{ return value<3>(); }

Referenced by Tester< Const, ref >::DoTests().

Here is the caller graph for this function:

◆ testCase()

template<bool Const, Ref ref = lvalue>
template<typename Visitor , typename Arg >
static void Tester< Const, ref >::testCase ( const Visitor &  visitor,
int  result,
Arg &  arg 
)
inlinestatic

Definition at line 108 of file VariantTest.cpp.

109{
110 if constexpr(Const)
111 {
112 const std::remove_reference_t<decltype(arg)> carg{ arg };
113 const VariantType cv{ carg };
114 REQUIRE(result == visitor(carg));
115 REQUIRE(result == Visit(visitor, cv));
116 if constexpr (ref != lvalue) {
117 REQUIRE(result == visitor(std::move(carg)));
118 REQUIRE(result == Visit(visitor, move(cv)));
119 }
120 }
121
122 {
123 VariantType v{ arg };
124 REQUIRE(result == visitor(arg));
125 REQUIRE(result == Visit(visitor, v));
126 if constexpr (ref != lvalue) {
127 REQUIRE(result == visitor(std::move(arg)));
128 REQUIRE(result == Visit(visitor, move(v)));
129 }
130 }
131};
MENUS_API void Visit(Visitor< Traits > &visitor, AudacityProject &project)
std::conditional_t< ref==lvalue, std::variant< MaybeConst< X >, MaybeConst< Y >, MaybeConst< Z >, MaybeConst< float >, MaybeConst< double >, MaybeConst< long double > >, std::variant< MaybeConst< Y >, MaybeConst< Z >, MaybeConst< float >, MaybeConst< double >, MaybeConst< long double > > > VariantType

References lvalue, and MenuRegistry::Visit().

Referenced by Tester< Const, ref >::DoTests().

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

◆ value()

template<bool Const, Ref ref = lvalue>
template<int Value>
static ResultType Tester< Const, ref >::value ( )
inlinestatic

Definition at line 43 of file VariantTest.cpp.

43 {
44 static MaybeConst<ValueType> x{ Value };
45 if constexpr (ref == rvalue)
46 return std::move(x);
47 else
48 return x;
49}
@ rvalue
Definition: VariantTest.cpp:17

References rvalue.


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