| 1 | // Boost.Range library |
|---|---|
| 2 | // |
| 3 | // Copyright Neil Groves 2010. 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) |
| 7 | // |
| 8 | // For more information, see http://www.boost.org/libs/range/ |
| 9 | // |
| 10 | |
| 11 | #include <boost/detail/workaround.hpp> |
| 12 | |
| 13 | #if BOOST_WORKAROUND(BOOST_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 |
| 16 | #endif |
| 17 | |
| 18 | #include <boost/range/begin.hpp> |
| 19 | #include <boost/test/unit_test.hpp> |
| 20 | #include <boost/test/test_tools.hpp> |
| 21 | #include <boost/test/included/unit_test.hpp> |
| 22 | |
| 23 | namespace mock_std |
| 24 | { |
| 25 | template<class SinglePassRange> |
| 26 | inline BOOST_DEDUCED_TYPENAME boost::range_iterator<SinglePassRange>::type |
| 27 | begin(SinglePassRange& rng) |
| 28 | { |
| 29 | return rng.begin(); |
| 30 | } |
| 31 | |
| 32 | template<class SinglePassRange> |
| 33 | inline BOOST_DEDUCED_TYPENAME boost::range_iterator<const SinglePassRange>::type |
| 34 | begin(const SinglePassRange& rng) |
| 35 | { |
| 36 | return rng.begin(); |
| 37 | } |
| 38 | |
| 39 | template<class SinglePassRange> |
| 40 | void mock_algorithm_using_begin(const SinglePassRange& rng) |
| 41 | { |
| 42 | BOOST_CHECK( begin(rng) == rng.begin() ); |
| 43 | } |
| 44 | |
| 45 | template<class SinglePassRange> |
| 46 | void mock_algorithm_using_begin(SinglePassRange& rng) |
| 47 | { |
| 48 | BOOST_CHECK( begin(rng) == rng.begin() ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | namespace boost |
| 53 | { |
| 54 | #ifdef BOOST_RANGE_SIMULATE_BEGIN_WITHOUT_ADL_NAMESPACE_BARRIER |
| 55 | template<class SinglePassRange> |
| 56 | inline BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type |
| 57 | begin(SinglePassRange& rng) |
| 58 | { |
| 59 | return rng.begin(); |
| 60 | } |
| 61 | |
| 62 | template<class SinglePassRange> |
| 63 | inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type |
| 64 | begin(const SinglePassRange& rng) |
| 65 | { |
| 66 | return rng.begin(); |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | class MockTestBeginCollection |
| 71 | { |
| 72 | public: |
| 73 | typedef char value_type; |
| 74 | typedef const char* const_pointer; |
| 75 | typedef char* pointer; |
| 76 | typedef const_pointer const_iterator; |
| 77 | typedef pointer iterator; |
| 78 | |
| 79 | MockTestBeginCollection() |
| 80 | : m_first() |
| 81 | , m_last() |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | const_iterator begin() const { return m_first; } |
| 86 | iterator begin() { return m_first; } |
| 87 | const_iterator end() const { return m_last; } |
| 88 | iterator end() { return m_last; } |
| 89 | |
| 90 | private: |
| 91 | iterator m_first; |
| 92 | iterator m_last; |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | namespace |
| 97 | { |
| 98 | void test_range_begin() |
| 99 | { |
| 100 | boost::MockTestBeginCollection c; |
| 101 | const boost::MockTestBeginCollection& const_c = c; |
| 102 | mock_std::mock_algorithm_using_begin(rng: const_c); |
| 103 | mock_std::mock_algorithm_using_begin(rng&: c); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | using boost::unit_test::test_suite; |
| 108 | |
| 109 | boost::unit_test::test_suite* |
| 110 | init_unit_test_suite( int argc, char* argv[] ) |
| 111 | { |
| 112 | boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - begin() ADL namespace barrier"); |
| 113 | |
| 114 | test->add( BOOST_TEST_CASE( &test_range_begin ) ); |
| 115 | |
| 116 | return test; |
| 117 | } |
| 118 | |
| 119 | |
| 120 |
