mirror of
https://github.com/boostorg/variant.git
synced 2026-07-21 13:43:36 +00:00
Fixed visitor result type deduction at rvalue ref operators
This commit is contained in:
@@ -108,6 +108,7 @@ apply_visitor(const Visitor& visitor, Visitable& visitable)
|
||||
|
||||
|
||||
#if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
|
||||
#define BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
|
||||
|
||||
// C++14
|
||||
namespace detail { namespace variant {
|
||||
@@ -125,14 +126,14 @@ struct result_multideduce1 {
|
||||
struct deduce_impl {
|
||||
typedef typename boost::mpl::next<It>::type next_t;
|
||||
typedef typename boost::mpl::deref<It>::type value_t;
|
||||
typedef decltype(true ? boost::declval< Visitor& >()( boost::declval< value_t& >() )
|
||||
typedef decltype(true ? boost::declval< Visitor& >()( boost::declval< value_t >() )
|
||||
: boost::declval< typename deduce_impl<next_t>::type >()) type;
|
||||
};
|
||||
|
||||
template <class Dummy>
|
||||
struct deduce_impl<last_it, Dummy> {
|
||||
typedef typename boost::mpl::deref<last_it>::type value_t;
|
||||
typedef decltype(boost::declval< Visitor& >()( boost::declval< value_t& >() )) type;
|
||||
typedef decltype(boost::declval< Visitor& >()( boost::declval< value_t >() )) type;
|
||||
};
|
||||
|
||||
typedef typename deduce_impl<begin_it>::type type;
|
||||
|
||||
@@ -62,6 +62,22 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS //BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
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)
|
||||
{
|
||||
@@ -124,6 +140,17 @@ int main()
|
||||
unary_test< check2_t >(var2);
|
||||
unary_test< check2_const_t >(cvar2);
|
||||
|
||||
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS //BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
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
|
||||
|
||||
//
|
||||
// binary tests
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user