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_DETAIL_IMPLEMENTATION_HELP_HPP |
| 12 | #define NDNBOOST_RANGE_DETAIL_IMPLEMENTATION_HELP_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 13 | |
| 14 | #include <ndnboost/range/config.hpp> |
| 15 | #include <ndnboost/range/detail/common.hpp> |
| 16 | #include <ndnboost/type_traits/is_same.hpp> |
| 17 | #include <cstddef> |
| 18 | #include <string.h> |
| 19 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 20 | #ifndef NDNBOOST_NO_CWCHAR |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 21 | #include <wchar.h> |
| 22 | #endif |
| 23 | |
| 24 | namespace ndnboost |
| 25 | { |
| 26 | namespace range_detail |
| 27 | { |
| 28 | template <typename T> |
| 29 | inline void boost_range_silence_warning( const T& ) { } |
| 30 | |
| 31 | ///////////////////////////////////////////////////////////////////// |
| 32 | // end() help |
| 33 | ///////////////////////////////////////////////////////////////////// |
| 34 | |
| 35 | inline const char* str_end( const char* s, const char* ) |
| 36 | { |
| 37 | return s + strlen( s ); |
| 38 | } |
| 39 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 40 | #ifndef NDNBOOST_NO_CWCHAR |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 41 | inline const wchar_t* str_end( const wchar_t* s, const wchar_t* ) |
| 42 | { |
| 43 | return s + wcslen( s ); |
| 44 | } |
| 45 | #else |
| 46 | inline const wchar_t* str_end( const wchar_t* s, const wchar_t* ) |
| 47 | { |
| 48 | if( s == 0 || s[0] == 0 ) |
| 49 | return s; |
| 50 | while( *++s != 0 ) |
| 51 | ; |
| 52 | return s; |
| 53 | } |
| 54 | #endif |
| 55 | |
| 56 | template< class Char > |
| 57 | inline Char* str_end( Char* s ) |
| 58 | { |
| 59 | return const_cast<Char*>( str_end( s, s ) ); |
| 60 | } |
| 61 | |
| 62 | template< class T, std::size_t sz > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 63 | inline T* array_end( T NDNBOOST_RANGE_ARRAY_REF()[sz] ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 64 | { |
| 65 | return boost_range_array + sz; |
| 66 | } |
| 67 | |
| 68 | template< class T, std::size_t sz > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 69 | inline const T* array_end( const T NDNBOOST_RANGE_ARRAY_REF()[sz] ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 70 | { |
| 71 | return boost_range_array + sz; |
| 72 | } |
| 73 | |
| 74 | ///////////////////////////////////////////////////////////////////// |
| 75 | // size() help |
| 76 | ///////////////////////////////////////////////////////////////////// |
| 77 | |
| 78 | template< class Char > |
| 79 | inline std::size_t str_size( const Char* const& s ) |
| 80 | { |
| 81 | return str_end( s ) - s; |
| 82 | } |
| 83 | |
| 84 | template< class T, std::size_t sz > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 85 | inline std::size_t array_size( T NDNBOOST_RANGE_ARRAY_REF()[sz] ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 86 | { |
| 87 | boost_range_silence_warning( boost_range_array ); |
| 88 | return sz; |
| 89 | } |
| 90 | |
| 91 | template< class T, std::size_t sz > |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 92 | inline std::size_t array_size( const T NDNBOOST_RANGE_ARRAY_REF()[sz] ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 93 | { |
| 94 | boost_range_silence_warning( boost_range_array ); |
| 95 | return sz; |
| 96 | } |
| 97 | |
| 98 | } // namespace 'range_detail' |
| 99 | |
| 100 | } // namespace 'boost' |
| 101 | |
| 102 | |
| 103 | #endif |