diff --git a/test/unary_visit_helper.hpp b/test/unary_visit_helper.hpp new file mode 100644 index 00000000..9b1689f7 --- /dev/null +++ b/test/unary_visit_helper.hpp @@ -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 variant_type; + variant_type v = udt2(); + + BOOST_TEST_EQ(1, + (boost::apply_visitor( + static_cast(visitor), + static_cast(v)) + )); + + v = udt1(); + + BOOST_TEST_EQ(0, + (boost::apply_visitor( + static_cast(visitor), + static_cast(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 diff --git a/test/variant_visit_test.cpp b/test/variant_visit_test.cpp index 3a8dd1b9..7c85de63 100644 --- a/test/variant_visit_test.cpp +++ b/test/variant_visit_test.cpp @@ -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 inline void unary_test(Variant& var, Checker* = 0) { @@ -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(udt2()))), 1 ); -#endif -#ifdef BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE - BOOST_TEST_EQ( (boost::apply_visitor( - rvalue_ref_decltype_visitor(), - boost::variant(udt2()))), 1 ); -#endif + #include "unary_visit_helper.hpp" // // binary tests