Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // Boost.Range library |
| 2 | // |
| 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) |
| 7 | // |
| 8 | // For more information, see http://www.boost.org/libs/range/ |
| 9 | // |
| 10 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 11 | #ifndef NDNBOOST_RANGE_BEGIN_HPP |
| 12 | #define NDNBOOST_RANGE_BEGIN_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 13 | |
| 14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
| 15 | # pragma once |
| 16 | #endif |
| 17 | |
| 18 | #include <ndnboost/range/config.hpp> |
| 19 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 20 | #ifdef NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 21 | #include <ndnboost/range/detail/begin.hpp> |
| 22 | #else |
| 23 | |
| 24 | #include <ndnboost/range/iterator.hpp> |
| 25 | |
| 26 | namespace ndnboost |
| 27 | { |
| 28 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 29 | #if !NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x564)) && \ |
| 30 | !NDNBOOST_WORKAROUND(__GNUC__, < 3) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 31 | /**/ |
| 32 | namespace range_detail |
| 33 | { |
| 34 | #endif |
| 35 | |
| 36 | ////////////////////////////////////////////////////////////////////// |
| 37 | // primary template |
| 38 | ////////////////////////////////////////////////////////////////////// |
| 39 | |
| 40 | template< typename C > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 41 | inline NDNBOOST_DEDUCED_TYPENAME range_iterator<C>::type |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 42 | range_begin( C& c ) |
| 43 | { |
| 44 | // |
| 45 | // If you get a compile-error here, it is most likely because |
| 46 | // you have not implemented range_begin() properly in |
| 47 | // the namespace of C |
| 48 | // |
| 49 | return c.begin(); |
| 50 | } |
| 51 | |
| 52 | ////////////////////////////////////////////////////////////////////// |
| 53 | // pair |
| 54 | ////////////////////////////////////////////////////////////////////// |
| 55 | |
| 56 | template< typename Iterator > |
| 57 | inline Iterator range_begin( const std::pair<Iterator,Iterator>& p ) |
| 58 | { |
| 59 | return p.first; |
| 60 | } |
| 61 | |
| 62 | template< typename Iterator > |
| 63 | inline Iterator range_begin( std::pair<Iterator,Iterator>& p ) |
| 64 | { |
| 65 | return p.first; |
| 66 | } |
| 67 | |
| 68 | ////////////////////////////////////////////////////////////////////// |
| 69 | // array |
| 70 | ////////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | // |
| 73 | // May this be discarded? Or is it needed for bad compilers? |
| 74 | // |
| 75 | template< typename T, std::size_t sz > |
| 76 | inline const T* range_begin( const T (&a)[sz] ) |
| 77 | { |
| 78 | return a; |
| 79 | } |
| 80 | |
| 81 | template< typename T, std::size_t sz > |
| 82 | inline T* range_begin( T (&a)[sz] ) |
| 83 | { |
| 84 | return a; |
| 85 | } |
| 86 | |
| 87 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 88 | #if !NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x564)) && \ |
| 89 | !NDNBOOST_WORKAROUND(__GNUC__, < 3) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 90 | /**/ |
| 91 | } // namespace 'range_detail' |
| 92 | #endif |
| 93 | |
| 94 | // Use a ADL namespace barrier to avoid ambiguity with other unqualified |
| 95 | // calls. This is particularly important with C++0x encouraging |
| 96 | // unqualified calls to begin/end. |
| 97 | namespace range_adl_barrier |
| 98 | { |
| 99 | |
| 100 | template< class T > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 101 | inline NDNBOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 102 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 103 | #if !NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x564)) && \ |
| 104 | !NDNBOOST_WORKAROUND(__GNUC__, < 3) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 105 | /**/ |
| 106 | using namespace range_detail; |
| 107 | #endif |
| 108 | return range_begin( r ); |
| 109 | } |
| 110 | |
| 111 | template< class T > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 112 | inline NDNBOOST_DEDUCED_TYPENAME range_iterator<const T>::type begin( const T& r ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 113 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 114 | #if !NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x564)) && \ |
| 115 | !NDNBOOST_WORKAROUND(__GNUC__, < 3) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 116 | /**/ |
| 117 | using namespace range_detail; |
| 118 | #endif |
| 119 | return range_begin( r ); |
| 120 | } |
| 121 | |
| 122 | } // namespace range_adl_barrier |
| 123 | } // namespace ndnboost |
| 124 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 125 | #endif // NDNBOOST_NO_FUNCTION_TEMPLATE_ORDERING |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 126 | |
| 127 | namespace ndnboost |
| 128 | { |
| 129 | namespace range_adl_barrier |
| 130 | { |
| 131 | template< class T > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 132 | inline NDNBOOST_DEDUCED_TYPENAME range_iterator<const T>::type |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 133 | const_begin( const T& r ) |
| 134 | { |
| 135 | return ndnboost::range_adl_barrier::begin( r ); |
| 136 | } |
| 137 | } // namespace range_adl_barrier |
| 138 | |
| 139 | using namespace range_adl_barrier; |
| 140 | } // namespace ndnboost |
| 141 | |
| 142 | #endif |
| 143 | |