Skip to content

Commit

Permalink
Merge df30110 into 0e122c3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kojoley committed Apr 23, 2019
2 parents 0e122c3 + df30110 commit 68d5d4f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 26 deletions.
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

0 comments on commit 68d5d4f

Please sign in to comment.