mirror of
https://github.com/boostorg/range.git
synced 2025-07-20 08:02:12 +02:00
*** empty log message ***
[SVN r24619]
This commit is contained in:
18
test/Jamfile
18
test/Jamfile
@ -74,20 +74,20 @@ test-suite range
|
||||
:
|
||||
: compat3_test
|
||||
]
|
||||
;
|
||||
|
||||
# [ run
|
||||
# adl_conformance.cpp
|
||||
# : :
|
||||
# :
|
||||
# : adl_conformance
|
||||
# ]
|
||||
# [ run
|
||||
# adl_conformance_no_using.cpp
|
||||
# : :
|
||||
# :
|
||||
# : adl_conformance_no_using_declaration
|
||||
# ]
|
||||
#
|
||||
# ;
|
||||
[ run
|
||||
adl_conformance_no_using.cpp
|
||||
: :
|
||||
:
|
||||
: adl_conformance_no_using_declaration
|
||||
]
|
||||
|
||||
;
|
||||
|
||||
}
|
||||
|
100
test/adl_conformance_no_using.cpp
Executable file
100
test/adl_conformance_no_using.cpp
Executable file
@ -0,0 +1,100 @@
|
||||
#include <iostream>
|
||||
|
||||
namespace A
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
int f( const T& x )
|
||||
{
|
||||
// Default:
|
||||
std::cout << 1 << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
int adl_f2( const T& x, int* )
|
||||
{
|
||||
return f( x );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
int adl_f( const T& x )
|
||||
{
|
||||
return adl_f2( x, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
int f( const T& x )
|
||||
{
|
||||
return detail::adl_f( x );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
int adl_f2( const T& x, int )
|
||||
{
|
||||
return detail::f( x );
|
||||
}
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class C {};
|
||||
/*
|
||||
// Optional:
|
||||
int f( const C& x )
|
||||
{
|
||||
std::cout << 2 << std::endl;
|
||||
}
|
||||
*/
|
||||
template< typename T >
|
||||
class D {};
|
||||
/*
|
||||
// Optional:
|
||||
template< typename T >
|
||||
int f( const D< T >& x )
|
||||
{
|
||||
std::cout << 3 << std::endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
namespace B
|
||||
{
|
||||
class C {};
|
||||
|
||||
// Optional:
|
||||
/* int f( const C& )
|
||||
{
|
||||
std::cout << 4 << std::endl;
|
||||
}
|
||||
*/
|
||||
template< typename T >
|
||||
class D {};
|
||||
/*
|
||||
// Optional:
|
||||
template< typename T >
|
||||
int f( const D< T >& x )
|
||||
{
|
||||
std::cout << 5 << std::endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
A::f( 42 );
|
||||
|
||||
A::C ac;
|
||||
A::f( ac );
|
||||
|
||||
A::D< int > ad;
|
||||
A::f( ad );
|
||||
|
||||
B::C bc;
|
||||
A::f( bc );
|
||||
|
||||
B::D< int > bd;
|
||||
A::f( bd );
|
||||
}
|
@ -1,197 +0,0 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# pragma warn -8091 // supress warning in Boost.Test
|
||||
# pragma warn -8057 // unused argument argc/argv in Boost.Test
|
||||
#endif
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
enum adl_types
|
||||
{
|
||||
unused,
|
||||
boost_namespace,
|
||||
templated_namespace,
|
||||
non_templated_namespace,
|
||||
global_namespace
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_detail
|
||||
{
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( Range& r )
|
||||
{
|
||||
return boost_namespace;
|
||||
}
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( const Range& r )
|
||||
{
|
||||
return boost_namespace;
|
||||
}
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator adl_begin( Range& r )
|
||||
{
|
||||
// create ADL hook
|
||||
return begin( r );
|
||||
}
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator adl_begin( const Range& r )
|
||||
{
|
||||
// create ADL hook
|
||||
return begin( r );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( Range& r )
|
||||
{
|
||||
return range_detail::adl_begin( r );
|
||||
}
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( const Range& r )
|
||||
{
|
||||
return range_detail::adl_begin( r );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace find_templated
|
||||
{
|
||||
template< class T >
|
||||
struct range
|
||||
{
|
||||
typedef adl_types iterator;
|
||||
|
||||
range() { /* allow const objects */ }
|
||||
iterator begin() { return unused; }
|
||||
iterator begin() const { return unused; }
|
||||
iterator end() { return unused; }
|
||||
iterator end() const { return unused; }
|
||||
};
|
||||
|
||||
//
|
||||
// A fully generic version here will create
|
||||
// ambiguity.
|
||||
//
|
||||
template< class T >
|
||||
inline typename range<T>::iterator begin( range<T>& r )
|
||||
{
|
||||
return templated_namespace;
|
||||
}
|
||||
|
||||
template< class T >
|
||||
inline typename range<T>::iterator begin( const range<T>& r )
|
||||
{
|
||||
return templated_namespace;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace find_non_templated
|
||||
{
|
||||
struct range
|
||||
{
|
||||
typedef adl_types iterator;
|
||||
|
||||
range() { /* allow const objects */ }
|
||||
iterator begin() { return unused; }
|
||||
iterator begin() const { return unused; }
|
||||
iterator end() { return unused; }
|
||||
iterator end() const { return unused; }
|
||||
};
|
||||
|
||||
inline range::iterator begin( range& r )
|
||||
{
|
||||
return non_templated_namespace;
|
||||
}
|
||||
|
||||
|
||||
inline range::iterator begin( const range& r )
|
||||
{
|
||||
return non_templated_namespace;
|
||||
}
|
||||
}
|
||||
|
||||
struct range
|
||||
{
|
||||
typedef adl_types iterator;
|
||||
|
||||
range() { /* allow const objects */ }
|
||||
iterator begin() { return unused; }
|
||||
iterator begin() const { return unused; }
|
||||
iterator end() { return unused; }
|
||||
iterator end() const { return unused; }
|
||||
};
|
||||
|
||||
inline range::iterator begin( range& r )
|
||||
{
|
||||
return global_namespace;
|
||||
}
|
||||
|
||||
inline range::iterator begin( const range& r )
|
||||
{
|
||||
return global_namespace;
|
||||
}
|
||||
|
||||
void check_adl_conformance()
|
||||
{
|
||||
find_templated::range<int> r;
|
||||
const find_templated::range<int> r2;
|
||||
find_non_templated::range r3;
|
||||
const find_non_templated::range r4;
|
||||
range r5;
|
||||
const range r6;
|
||||
|
||||
//
|
||||
// Notice how ADL kicks in even when we have qualified
|
||||
// notation!
|
||||
//
|
||||
|
||||
|
||||
BOOST_CHECK( boost::begin( r ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r2 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r3 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r4 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r5 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r6 ) != boost_namespace );
|
||||
|
||||
BOOST_CHECK_EQUAL( boost::begin( r ), templated_namespace ) ;
|
||||
BOOST_CHECK_EQUAL( boost::begin( r2 ), templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r3 ), non_templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r4 ), non_templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r5 ), global_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r6 ), global_namespace );
|
||||
}
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_adl_conformance ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user