From a6e1f784d044c40cc9d742deebf4f995a325535f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Fri, 20 Aug 2004 18:59:28 +0000 Subject: [PATCH] *** empty log message *** [SVN r24619] --- test/Jamfile | 18 +- test/adl_conformance_no_using.cpp | 100 +++++++++ test/adl_conformance_no_using_declaration.cpp | 197 ------------------ 3 files changed, 109 insertions(+), 206 deletions(-) create mode 100755 test/adl_conformance_no_using.cpp delete mode 100755 test/adl_conformance_no_using_declaration.cpp diff --git a/test/Jamfile b/test/Jamfile index 767f1d2..b989781 100755 --- a/test/Jamfile +++ b/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 + ] + + ; } diff --git a/test/adl_conformance_no_using.cpp b/test/adl_conformance_no_using.cpp new file mode 100755 index 0000000..60d7cea --- /dev/null +++ b/test/adl_conformance_no_using.cpp @@ -0,0 +1,100 @@ +#include + +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 ); +} diff --git a/test/adl_conformance_no_using_declaration.cpp b/test/adl_conformance_no_using_declaration.cpp deleted file mode 100755 index f679004..0000000 --- a/test/adl_conformance_no_using_declaration.cpp +++ /dev/null @@ -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 - -#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; -} - -