Skip to content

Commit df30110

Browse files
committed
Additional visitor tests
Currently failing tests are commented out for now.
1 parent 0e122c3 commit df30110

File tree

2 files changed

+84
-26
lines changed

2 files changed

+84
-26
lines changed

test/unary_visit_helper.hpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#if defined(DECLTYPE_VISITOR)
2+
{
3+
struct visitor_type
4+
{
5+
#if !DECLTYPE_VISITOR
6+
typedef int result_type;
7+
#endif
8+
int operator()(udt1 VARIANT_QUALIFIERS) VISITOR_QUALIFIERS { return 0; }
9+
int operator()(udt2 VARIANT_QUALIFIERS) VISITOR_QUALIFIERS { return 1; }
10+
} visitor;
11+
12+
typedef boost::variant<udt1, udt2> variant_type;
13+
variant_type v = udt2();
14+
15+
BOOST_TEST_EQ(1,
16+
(boost::apply_visitor(
17+
static_cast<visitor_type VISITOR_QUALIFIERS>(visitor),
18+
static_cast<variant_type VARIANT_QUALIFIERS>(v))
19+
));
20+
21+
v = udt1();
22+
23+
BOOST_TEST_EQ(0,
24+
(boost::apply_visitor(
25+
static_cast<visitor_type VISITOR_QUALIFIERS>(visitor),
26+
static_cast<variant_type VARIANT_QUALIFIERS>(v))
27+
));
28+
}
29+
#elif defined(VARIANT_QUALIFIERS)
30+
31+
#define DECLTYPE_VISITOR 0
32+
#include "unary_visit_helper.hpp"
33+
#undef DECLTYPE_VISITOR
34+
#ifdef BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
35+
#define DECLTYPE_VISITOR 1
36+
#include "unary_visit_helper.hpp"
37+
#undef DECLTYPE_VISITOR
38+
#endif
39+
40+
#elif defined(VISITOR_QUALIFIERS)
41+
42+
#define VARIANT_QUALIFIERS
43+
#include "unary_visit_helper.hpp"
44+
#undef VARIANT_QUALIFIERS
45+
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS // BOOST_NO_CXX11_RVALUE_REFERENCES is not enough for disabling buggy GCCs < 4.8
46+
#define VARIANT_QUALIFIERS &
47+
#include "unary_visit_helper.hpp"
48+
#undef VARIANT_QUALIFIERS
49+
#define VARIANT_QUALIFIERS const&
50+
#include "unary_visit_helper.hpp"
51+
#undef VARIANT_QUALIFIERS
52+
#define VARIANT_QUALIFIERS &&
53+
#include "unary_visit_helper.hpp"
54+
#undef VARIANT_QUALIFIERS
55+
#define VARIANT_QUALIFIERS const&&
56+
#include "unary_visit_helper.hpp"
57+
#undef VARIANT_QUALIFIERS
58+
#endif
59+
60+
#elif !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
61+
62+
//#define VISITOR_QUALIFIERS
63+
//#include "unary_visit_helper.hpp"
64+
//#undef VISITOR_QUALIFIERS
65+
#define VISITOR_QUALIFIERS const
66+
#include "unary_visit_helper.hpp"
67+
#undef VISITOR_QUALIFIERS
68+
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS
69+
#define VISITOR_QUALIFIERS &
70+
#include "unary_visit_helper.hpp"
71+
#undef VISITOR_QUALIFIERS
72+
#define VISITOR_QUALIFIERS const&
73+
#include "unary_visit_helper.hpp"
74+
#undef VISITOR_QUALIFIERS
75+
//#define VISITOR_QUALIFIERS &&
76+
//#include "unary_visit_helper.hpp"
77+
//#undef VISITOR_QUALIFIERS
78+
//#define VISITOR_QUALIFIERS const&&
79+
//#include "unary_visit_helper.hpp"
80+
//#undef VISITOR_QUALIFIERS
81+
#endif
82+
83+
#endif

test/variant_visit_test.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,6 @@ class binary_check_content_type
6262

6363
};
6464

65-
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS // BOOST_NO_CXX11_RVALUE_REFERENCES is not enough for disabling buggy GCCs < 4.8
66-
struct rvalue_ref_visitor
67-
{
68-
typedef int result_type;
69-
int operator()(udt1&&) const { return 0; }
70-
int operator()(udt2&&) const { return 1; }
71-
};
72-
#endif
73-
#ifdef BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
74-
struct rvalue_ref_decltype_visitor
75-
{
76-
int operator()(udt1&&) const { return 0; }
77-
int operator()(udt2&&) const { return 1; }
78-
};
79-
#endif
80-
8165
template <typename Checker, typename Variant>
8266
inline void unary_test(Variant& var, Checker* = 0)
8367
{
@@ -140,16 +124,7 @@ int main()
140124
unary_test< check2_t >(var2);
141125
unary_test< check2_const_t >(cvar2);
142126

143-
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS // BOOST_NO_CXX11_RVALUE_REFERENCES is not enough for disabling buggy GCCs < 4.8
144-
BOOST_TEST_EQ( (boost::apply_visitor(
145-
rvalue_ref_visitor(),
146-
boost::variant<udt1, udt2>(udt2()))), 1 );
147-
#endif
148-
#ifdef BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
149-
BOOST_TEST_EQ( (boost::apply_visitor(
150-
rvalue_ref_decltype_visitor(),
151-
boost::variant<udt1, udt2>(udt2()))), 1 );
152-
#endif
127+
#include "unary_visit_helper.hpp"
153128

154129
//
155130
// binary tests

0 commit comments

Comments
 (0)