implementation_help.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef BOOST_RANGE_DETAIL_IMPLEMENTATION_HELP_HPP
  11. #define BOOST_RANGE_DETAIL_IMPLEMENTATION_HELP_HPP
  12. #include <boost/range/config.hpp>
  13. #include <boost/range/detail/common.hpp>
  14. #include <boost/type_traits/is_same.hpp>
  15. #include <cstddef>
  16. #include <string.h>
  17. #ifndef BOOST_NO_CWCHAR
  18. #include <wchar.h>
  19. #endif
  20. namespace boost
  21. {
  22. namespace range_detail
  23. {
  24. template <typename T>
  25. inline void boost_range_silence_warning( const T& ) { }
  26. /////////////////////////////////////////////////////////////////////
  27. // end() help
  28. /////////////////////////////////////////////////////////////////////
  29. inline const char* str_end( const char* s, const char* )
  30. {
  31. return s + strlen( s );
  32. }
  33. #ifndef BOOST_NO_CWCHAR
  34. inline const wchar_t* str_end( const wchar_t* s, const wchar_t* )
  35. {
  36. return s + wcslen( s );
  37. }
  38. #else
  39. inline const wchar_t* str_end( const wchar_t* s, const wchar_t* )
  40. {
  41. if( s == 0 || s[0] == 0 )
  42. return s;
  43. while( *++s != 0 )
  44. ;
  45. return s;
  46. }
  47. #endif
  48. template< class Char >
  49. inline Char* str_end( Char* s )
  50. {
  51. return const_cast<Char*>( str_end( s, s ) );
  52. }
  53. template< class T, std::size_t sz >
  54. BOOST_CONSTEXPR inline T* array_end( T BOOST_RANGE_ARRAY_REF()[sz] ) BOOST_NOEXCEPT
  55. {
  56. return boost_range_array + sz;
  57. }
  58. template< class T, std::size_t sz >
  59. BOOST_CONSTEXPR inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz] ) BOOST_NOEXCEPT
  60. {
  61. return boost_range_array + sz;
  62. }
  63. /////////////////////////////////////////////////////////////////////
  64. // size() help
  65. /////////////////////////////////////////////////////////////////////
  66. template< class Char >
  67. inline std::size_t str_size( const Char* const& s )
  68. {
  69. return str_end( s ) - s;
  70. }
  71. template< class T, std::size_t sz >
  72. inline std::size_t array_size( T BOOST_RANGE_ARRAY_REF()[sz] )
  73. {
  74. boost_range_silence_warning( boost_range_array );
  75. return sz;
  76. }
  77. template< class T, std::size_t sz >
  78. inline std::size_t array_size( const T BOOST_RANGE_ARRAY_REF()[sz] )
  79. {
  80. boost_range_silence_warning( boost_range_array );
  81. return sz;
  82. }
  83. inline bool is_same_address(const void* l, const void* r)
  84. {
  85. return l == r;
  86. }
  87. template<class T1, class T2>
  88. inline bool is_same_object(const T1& l, const T2& r)
  89. {
  90. return range_detail::is_same_address(&l, &r);
  91. }
  92. } // namespace 'range_detail'
  93. } // namespace 'boost'
  94. #endif