diff --git a/test/Jamfile b/test/Jamfile index 8320cd5..0c552c7 100755 --- a/test/Jamfile +++ b/test/Jamfile @@ -68,12 +68,6 @@ test-suite range : : compat1_test ] -# [ run -# compat2.cpp -# : : -# : -# : compat2_test -# ] [ run compat3.cpp : : @@ -87,5 +81,12 @@ test-suite range : : adl_conformance ] + [ run + adl_conformance_no_using_declaration.cpp + : : + : + : adl_conformance_no_using_declaration + ] + ; } diff --git a/test/adl_conformance_no_using_declaration.cpp b/test/adl_conformance_no_using_declaration.cpp new file mode 100755 index 0000000..f679004 --- /dev/null +++ b/test/adl_conformance_no_using_declaration.cpp @@ -0,0 +1,197 @@ +// 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 + +#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 +#include + +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::iterator begin( range& r ) + { + return templated_namespace; + } + + template< class T > + inline typename range::iterator begin( const range& 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 r; + const find_templated::range 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 + +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; +} + +