Remove reference-collapsing overloads of ref and cref.

This commit is contained in:
Peter Dimov
2014-07-15 12:06:55 +03:00
parent 1bd554f5ad
commit 0fa07e72eb
2 changed files with 40 additions and 33 deletions

View File

@@ -1,5 +1,8 @@
//
// Test for ref(ref(x))
// Test that ref(ref(x)) does NOT collapse to ref(x)
//
// This irregularity of std::ref is questionable and breaks
// existing Boost code such as proto::make_expr
//
// Copyright 2014 Peter Dimov
//
@@ -11,28 +14,50 @@
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
template<class T> void test( T const & t )
{
{
boost::reference_wrapper< T const > r = boost::ref( t );
BOOST_TEST_EQ( &r.get(), &t );
}
{
boost::reference_wrapper< T const > r = boost::cref( t );
BOOST_TEST_EQ( &r.get(), &t );
}
}
template<class T> void test_nonconst( T & t )
{
{
boost::reference_wrapper< T > r = boost::ref( t );
BOOST_TEST_EQ( &r.get(), &t );
}
{
boost::reference_wrapper< T const > r = boost::cref( t );
BOOST_TEST_EQ( &r.get(), &t );
}
}
int main()
{
int x = 0;
test( x );
test( boost::ref( x ) );
test( boost::cref( x ) );
test_nonconst( x );
{
boost::reference_wrapper< int > r = boost::ref( boost::ref( x ) );
BOOST_TEST_EQ( &r.get(), &x );
boost::reference_wrapper< int > r = boost::ref( x );
test_nonconst( r );
}
{
boost::reference_wrapper< int const > r = boost::ref( boost::cref( x ) );
BOOST_TEST_EQ( &r.get(), &x );
}
{
boost::reference_wrapper< int const > r = boost::cref( boost::ref( x ) );
BOOST_TEST_EQ( &r.get(), &x );
}
{
boost::reference_wrapper< int const > r = boost::cref( boost::cref( x ) );
BOOST_TEST_EQ( &r.get(), &x );
boost::reference_wrapper< int const > r = boost::cref( x );
test_nonconst( r );
}
return boost::report_errors();