3 // Copyright Thorsten Ottosen 2003-2004. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/range/
11 #include <boost/detail/workaround.hpp>
13 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
14 # pragma warn -8091 // suppress warning in Boost.Test
15 # pragma warn -8057 // unused argument argc/argv in Boost.Test
18 #include <boost/test/unit_test.hpp>
19 #include <boost/test/test_tools.hpp>
26 non_templated_namespace,
30 // Use boost_test rather than boost as the namespace for this test
31 // to allow the test framework to use boost::begin() etc. without
32 // violating the One Defintion Rule.
35 namespace range_detail
37 template< class Range >
38 inline typename Range::iterator begin( Range& r )
40 return boost_namespace;
43 template< class Range >
44 inline typename Range::iterator begin( const Range& r )
46 return boost_namespace;
51 template< class Range >
52 inline typename Range::iterator begin( Range& r )
54 using range_detail::begin; // create ADL hook
58 template< class Range >
59 inline typename Range::iterator begin( const Range& r )
61 using range_detail::begin; // create ADL hook
67 namespace find_templated
72 typedef adl_types iterator;
74 range() { /* allow const objects */ }
75 iterator begin() { return unused; }
76 iterator begin() const { return unused; }
77 iterator end() { return unused; }
78 iterator end() const { return unused; }
82 // A fully generic version here will create
86 inline typename range<T>::iterator begin( range<T>& r )
88 return templated_namespace;
92 inline typename range<T>::iterator begin( const range<T>& r )
94 return templated_namespace;
99 namespace find_non_templated
103 typedef adl_types iterator;
105 range() { /* allow const objects */ }
106 iterator begin() { return unused; }
107 iterator begin() const { return unused; }
108 iterator end() { return unused; }
109 iterator end() const { return unused; }
112 inline range::iterator begin( range& r )
114 return non_templated_namespace;
118 inline range::iterator begin( const range& r )
120 return non_templated_namespace;
126 typedef adl_types iterator;
128 range() { /* allow const objects */ }
129 iterator begin() { return unused; }
130 iterator begin() const { return unused; }
131 iterator end() { return unused; }
132 iterator end() const { return unused; }
135 inline range::iterator begin( range& r )
137 return global_namespace;
140 inline range::iterator begin( const range& r )
142 return global_namespace;
145 void check_adl_conformance()
147 find_templated::range<int> r;
148 const find_templated::range<int> r2;
149 find_non_templated::range r3;
150 const find_non_templated::range r4;
155 // Notice how ADL kicks in even when we have qualified
160 BOOST_CHECK( boost_test::begin( r ) != boost_namespace );
161 BOOST_CHECK( boost_test::begin( r2 ) != boost_namespace );
162 BOOST_CHECK( boost_test::begin( r3 ) != boost_namespace );
163 BOOST_CHECK( boost_test::begin( r4 ) != boost_namespace );
164 BOOST_CHECK( boost_test::begin( r5 ) != boost_namespace );
165 BOOST_CHECK( boost_test::begin( r6 ) != boost_namespace );
167 BOOST_CHECK_EQUAL( boost_test::begin( r ), templated_namespace ) ;
168 BOOST_CHECK_EQUAL( boost_test::begin( r2 ), templated_namespace );
169 BOOST_CHECK_EQUAL( boost_test::begin( r3 ), non_templated_namespace );
170 BOOST_CHECK_EQUAL( boost_test::begin( r4 ), non_templated_namespace );
171 BOOST_CHECK_EQUAL( boost_test::begin( r5 ), global_namespace );
172 BOOST_CHECK_EQUAL( boost_test::begin( r6 ), global_namespace );
175 #include <boost/test/included/unit_test.hpp>
177 using boost::unit_test::test_suite;
179 test_suite* init_unit_test_suite( int argc, char* argv[] )
181 test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
183 test->add( BOOST_TEST_CASE( &check_adl_conformance ) );