19 using Variant_t = std::variant<int, char, std::string, QString, double, float>;
35 void VisitorTest::testBasicVisitor ()
39 [] (
char) {
return true; },
40 [] (
int) {
return false; },
41 [] (std::string) {
return false; },
43 [] (
double) {
return false; },
44 [] (
float) {
return false; });
48 void VisitorTest::testBasicVisitorGenericFallback ()
52 [] (
char) {
return true; },
53 [] (
int) {
return false; },
54 [] (
auto) {
return false; });
58 void VisitorTest::testBasicVisitorCoercion ()
62 [] (
int) {
return true; },
63 [] (std::string) {
return false; },
65 [] (
double) {
return false; },
66 [] (
float) {
return false; });
70 void VisitorTest::testBasicVisitorCoercionGenericFallback ()
74 [] (
int) {
return false; },
76 [] (
auto) {
return true; });
80#define NC nc = std::unique_ptr<int> {}
82 void VisitorTest::testNonCopyableFunctors ()
86 [
NC] (
char) {
return true; },
87 [
NC] (
int) {
return false; },
88 [
NC] (std::string) {
return false; },
91 [
NC] (
float) {
return false; });
96 void VisitorTest::testAcceptsRValueRef ()
99 [] (
char) {
return true; },
100 [] (
auto) {
return false; });
104 void VisitorTest::testLValueRef ()
113 void VisitorTest::testLValueRef2 ()
116 Visit (
v, [] (
auto&
s) ->
int& {
return s.field1; }) = 10;
117 const auto&
res =
Visit (
v, [] (
const auto&
s) ->
const int& {
return s.field1; });
121 void VisitorTest::testPrepareVisitor ()
126 [] (
char) {
return true; },
127 [] (
int) {
return false; },
128 [] (std::string) {
return false; },
129 [] (
QString) {
return false; },
130 [] (
double) {
return false; },
131 [] (
float) {
return false; }
138 void VisitorTest::testPrepareVisitorConst ()
143 [] (
char) {
return true; },
144 [] (
int) {
return false; },
145 [] (std::string) {
return false; },
146 [] (
QString) {
return false; },
147 [] (
double) {
return false; },
148 [] (
float) {
return false; }
155 void VisitorTest::testPrepareVisitorRValue ()
159 [] (
char) {
return true; },
160 [] (
int) {
return false; },
161 [] (std::string) {
return false; },
162 [] (
QString) {
return false; },
163 [] (
double) {
return false; },
164 [] (
float) {
return false; }
171 void VisitorTest::testPrepareVisitorFinally ()
179 [] (
char) {
return true; },
180 [] (
auto) {
return false; }
181 }.Finally ([&
fin] {
fin =
true; });
188 void VisitorTest::testPrepareJustAutoVisitor ()
190 using Variant_t = std::variant<int, double, float>;
194 [] (
auto e) {
return std::to_string (
e); }
201 void VisitorTest::testPrepareRecursiveVisitor ()
204 using Variant_t = std::variant<SubVariant_t, QString>;
209 Visitor { [] (
auto e) {
return QString::fromStdString (std::to_string (
e)); } }
216 void VisitorTest::testPrepareVisitorMutable ()
221 [] (
int)
mutable {
return true; },
222 [] (
auto)
mutable {
return false; }
Container< T > Filter(const Container< T > &c, F f)
auto Visit(const Either< Left, Right > &either, Args &&... args)
std::variant< int, char, std::string, QString, double, float > Variant_t
Visitor(Args &&...) -> Visitor< Void, Args... >
std::variant< S1, S2 > SVariant_t