| 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 | |
|---|
| 11 | #ifndef BOOST_RANGE_DETAIL_IMPLEMENTATION_HELP_HPP |
|---|
| 12 | #define BOOST_RANGE_DETAIL_IMPLEMENTATION_HELP_HPP |
|---|
| 13 | |
|---|
| 14 | #include <boost/range/config.hpp> |
|---|
| 15 | #include <boost/range/detail/common.hpp> |
|---|
| 16 | #include <boost/type_traits/is_same.hpp> |
|---|
| 17 | #include <cstddef> |
|---|
| 18 | #include <string.h> |
|---|
| 19 | |
|---|
| 20 | #ifndef BOOST_NO_CWCHAR |
|---|
| 21 | #include <wchar.h> |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | namespace boost |
|---|
| 25 | { |
|---|
| 26 | namespace range_detail |
|---|
| 27 | { |
|---|
| 28 | |
|---|
| 29 | ///////////////////////////////////////////////////////////////////// |
|---|
| 30 | // end() help |
|---|
| 31 | ///////////////////////////////////////////////////////////////////// |
|---|
| 32 | |
|---|
| 33 | inline const char* str_end( const char* s, const char* ) |
|---|
| 34 | { |
|---|
| 35 | return s + strlen( s ); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | #ifndef BOOST_NO_CWCHAR |
|---|
| 39 | inline const wchar_t* str_end( const wchar_t* s, const wchar_t* ) |
|---|
| 40 | { |
|---|
| 41 | return s + wcslen( s ); |
|---|
| 42 | } |
|---|
| 43 | #else |
|---|
| 44 | inline const wchar_t* str_end( const wchar_t* s, const wchar_t* ) |
|---|
| 45 | { |
|---|
| 46 | if( s == 0 || s[0] == 0 ) |
|---|
| 47 | return s; |
|---|
| 48 | while( *++s != 0 ) |
|---|
| 49 | ; |
|---|
| 50 | return s; |
|---|
| 51 | } |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | template< class Char > |
|---|
| 55 | inline Char* str_end( Char* s ) |
|---|
| 56 | { |
|---|
| 57 | return const_cast<Char*>( str_end( s, s ) ); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | template< class T, std::size_t sz > |
|---|
| 61 | inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz], int ) |
|---|
| 62 | { |
|---|
| 63 | return boost_range_array + sz; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | template< class T, std::size_t sz > |
|---|
| 67 | inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz], int ) |
|---|
| 68 | { |
|---|
| 69 | return boost_range_array + sz; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | template< class T, std::size_t sz > |
|---|
| 73 | inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) |
|---|
| 74 | { |
|---|
| 75 | return boost_range_array + sz - 1; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | template< class T, std::size_t sz > |
|---|
| 79 | inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) |
|---|
| 80 | { |
|---|
| 81 | return boost_range_array + sz - 1; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | template< class T, std::size_t sz > |
|---|
| 85 | inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz] ) |
|---|
| 86 | { |
|---|
| 87 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<char,T>::value || is_same<wchar_t,T>::value, |
|---|
| 88 | char_or_wchar_t_array_tag, |
|---|
| 89 | int >::type tag; |
|---|
| 90 | |
|---|
| 91 | return array_end<T,sz>( boost_range_array, tag() ); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | template< class T, std::size_t sz > |
|---|
| 95 | inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz] ) |
|---|
| 96 | { |
|---|
| 97 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<char,T>::value || is_same<wchar_t,T>::value, |
|---|
| 98 | char_or_wchar_t_array_tag, |
|---|
| 99 | int >::type tag; |
|---|
| 100 | |
|---|
| 101 | return array_end<T,sz>( boost_range_array, tag() ); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | ///////////////////////////////////////////////////////////////////// |
|---|
| 105 | // size() help |
|---|
| 106 | ///////////////////////////////////////////////////////////////////// |
|---|
| 107 | |
|---|
| 108 | template< class Char > |
|---|
| 109 | inline std::size_t str_size( const Char* const& s ) |
|---|
| 110 | { |
|---|
| 111 | return str_end( s ) - s; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | template< class T, std::size_t sz > |
|---|
| 115 | inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz], int ) |
|---|
| 116 | { |
|---|
| 117 | return sz; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | template< class T, std::size_t sz > |
|---|
| 121 | inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz], int ) |
|---|
| 122 | { |
|---|
| 123 | return sz; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | template< class T, std::size_t sz > |
|---|
| 127 | inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) |
|---|
| 128 | { |
|---|
| 129 | return sz - 1; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | template< class T, std::size_t sz > |
|---|
| 133 | inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz], char_or_wchar_t_array_tag ) |
|---|
| 134 | { |
|---|
| 135 | return sz - 1; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | template< class T, std::size_t sz > |
|---|
| 139 | inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz] ) |
|---|
| 140 | { |
|---|
| 141 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<const char,T>::value || is_same<const wchar_t,T>::value || |
|---|
| 142 | is_same<char,T>::value || is_same<wchar_t,T>::value, |
|---|
| 143 | char_or_wchar_t_array_tag, |
|---|
| 144 | int >::type tag; |
|---|
| 145 | return array_size<T,sz>( boost_range_array, tag() ); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | template< class T, std::size_t sz > |
|---|
| 149 | inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz] ) |
|---|
| 150 | { |
|---|
| 151 | typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< is_same<char,T>::value || is_same<wchar_t,T>::value, |
|---|
| 152 | char_or_wchar_t_array_tag, |
|---|
| 153 | int >::type tag; |
|---|
| 154 | return array_size<T,sz>( boost_range_array, tag() ); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | } // namespace 'range_detail' |
|---|
| 158 | |
|---|
| 159 | } // namespace 'boost' |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | #endif |
|---|