Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions test/unary_visit_helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#if defined(DECLTYPE_VISITOR)
{
struct visitor_type
{
#if !DECLTYPE_VISITOR
typedef int result_type;
#endif
int operator()(udt1 VARIANT_QUALIFIERS) VISITOR_QUALIFIERS { return 0; }
int operator()(udt2 VARIANT_QUALIFIERS) VISITOR_QUALIFIERS { return 1; }
} visitor;

typedef boost::variant<udt1, udt2> variant_type;
variant_type v = udt2();

BOOST_TEST_EQ(1,
(boost::apply_visitor(
static_cast<visitor_type VISITOR_QUALIFIERS>(visitor),
static_cast<variant_type VARIANT_QUALIFIERS>(v))
));

v = udt1();

BOOST_TEST_EQ(0,
(boost::apply_visitor(
static_cast<visitor_type VISITOR_QUALIFIERS>(visitor),
static_cast<variant_type VARIANT_QUALIFIERS>(v))
));
}
#elif defined(VARIANT_QUALIFIERS)

#define DECLTYPE_VISITOR 0
#include "unary_visit_helper.hpp"
#undef DECLTYPE_VISITOR
#ifdef BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
#define DECLTYPE_VISITOR 1
#include "unary_visit_helper.hpp"
#undef DECLTYPE_VISITOR
#endif

#elif defined(VISITOR_QUALIFIERS)

#define VARIANT_QUALIFIERS
#include "unary_visit_helper.hpp"
#undef VARIANT_QUALIFIERS
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS // BOOST_NO_CXX11_RVALUE_REFERENCES is not enough for disabling buggy GCCs < 4.8
#define VARIANT_QUALIFIERS &
#include "unary_visit_helper.hpp"
#undef VARIANT_QUALIFIERS
#define VARIANT_QUALIFIERS const&
#include "unary_visit_helper.hpp"
#undef VARIANT_QUALIFIERS
#define VARIANT_QUALIFIERS &&
#include "unary_visit_helper.hpp"
#undef VARIANT_QUALIFIERS
#define VARIANT_QUALIFIERS const&&
#include "unary_visit_helper.hpp"
#undef VARIANT_QUALIFIERS
#endif

#elif !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)

//#define VISITOR_QUALIFIERS
//#include "unary_visit_helper.hpp"
//#undef VISITOR_QUALIFIERS
#define VISITOR_QUALIFIERS const
#include "unary_visit_helper.hpp"
#undef VISITOR_QUALIFIERS
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS
#define VISITOR_QUALIFIERS &
#include "unary_visit_helper.hpp"
#undef VISITOR_QUALIFIERS
#define VISITOR_QUALIFIERS const&
#include "unary_visit_helper.hpp"
#undef VISITOR_QUALIFIERS
//#define VISITOR_QUALIFIERS &&
//#include "unary_visit_helper.hpp"
//#undef VISITOR_QUALIFIERS
//#define VISITOR_QUALIFIERS const&&
//#include "unary_visit_helper.hpp"
//#undef VISITOR_QUALIFIERS
#endif

#endif
27 changes: 1 addition & 26 deletions test/variant_visit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,6 @@ class binary_check_content_type

};

#ifndef BOOST_NO_CXX11_REF_QUALIFIERS // BOOST_NO_CXX11_RVALUE_REFERENCES is not enough for disabling buggy GCCs < 4.8
struct rvalue_ref_visitor
{
typedef int result_type;
int operator()(udt1&&) const { return 0; }
int operator()(udt2&&) const { return 1; }
};
#endif
#ifdef BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
struct rvalue_ref_decltype_visitor
{
int operator()(udt1&&) const { return 0; }
int operator()(udt2&&) const { return 1; }
};
#endif

template <typename Checker, typename Variant>
inline void unary_test(Variant& var, Checker* = 0)
{
Expand Down Expand Up @@ -140,16 +124,7 @@ int main()
unary_test< check2_t >(var2);
unary_test< check2_const_t >(cvar2);

#ifndef BOOST_NO_CXX11_REF_QUALIFIERS // BOOST_NO_CXX11_RVALUE_REFERENCES is not enough for disabling buggy GCCs < 4.8
BOOST_TEST_EQ( (boost::apply_visitor(
rvalue_ref_visitor(),
boost::variant<udt1, udt2>(udt2()))), 1 );
#endif
#ifdef BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
BOOST_TEST_EQ( (boost::apply_visitor(
rvalue_ref_decltype_visitor(),
boost::variant<udt1, udt2>(udt2()))), 1 );
#endif
#include "unary_visit_helper.hpp"

//
// binary tests
Expand Down