/Src/Dependencies/Boost/boost/range/as_literal.hpp

http://hadesmem.googlecode.com/ · C++ Header · 127 lines · 90 code · 23 blank · 14 comment · 1 complexity · 0f235de76e96d9d70c216b5970d080e6 MD5 · raw file

  1. // Boost.Range library
  2. //
  3. // Copyright Thorsten Ottosen 2006. 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_AS_LITERAL_HPP
  11. #define BOOST_RANGE_AS_LITERAL_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif
  15. #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  16. #include <boost/range/detail/as_literal.hpp>
  17. #else
  18. #include <boost/range/iterator_range.hpp>
  19. #include <boost/range/detail/str_types.hpp>
  20. #include <boost/detail/workaround.hpp>
  21. #include <cstring>
  22. #ifndef BOOST_NO_CWCHAR
  23. #include <cwchar>
  24. #endif
  25. namespace boost
  26. {
  27. namespace range_detail
  28. {
  29. inline std::size_t length( const char* s )
  30. {
  31. return strlen( s );
  32. }
  33. #ifndef BOOST_NO_CWCHAR
  34. inline std::size_t length( const wchar_t* s )
  35. {
  36. return wcslen( s );
  37. }
  38. #endif
  39. //
  40. // Remark: the compiler cannot choose between T* and T[sz]
  41. // overloads, so we must put the T* internal to the
  42. // unconstrained version.
  43. //
  44. inline bool is_char_ptr( char* )
  45. {
  46. return true;
  47. }
  48. inline bool is_char_ptr( const char* )
  49. {
  50. return true;
  51. }
  52. #ifndef BOOST_NO_CWCHAR
  53. inline bool is_char_ptr( wchar_t* )
  54. {
  55. return true;
  56. }
  57. inline bool is_char_ptr( const wchar_t* )
  58. {
  59. return true;
  60. }
  61. #endif
  62. template< class T >
  63. inline long is_char_ptr( T /* r */ )
  64. {
  65. return 0L;
  66. }
  67. template< class T >
  68. inline iterator_range<T*>
  69. make_range( T* const r, bool )
  70. {
  71. return iterator_range<T*>( r, r + length(r) );
  72. }
  73. template< class T >
  74. inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<T>::type>
  75. make_range( T& r, long )
  76. {
  77. return boost::make_iterator_range( r );
  78. }
  79. }
  80. template< class Range >
  81. inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<Range>::type>
  82. as_literal( Range& r )
  83. {
  84. return range_detail::make_range( r, range_detail::is_char_ptr(r) );
  85. }
  86. template< class Range >
  87. inline iterator_range<BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type>
  88. as_literal( const Range& r )
  89. {
  90. return range_detail::make_range( r, range_detail::is_char_ptr(r) );
  91. }
  92. template< class Char, std::size_t sz >
  93. inline iterator_range<Char*> as_literal( Char (&arr)[sz] )
  94. {
  95. return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
  96. }
  97. template< class Char, std::size_t sz >
  98. inline iterator_range<const Char*> as_literal( const Char (&arr)[sz] )
  99. {
  100. return range_detail::make_range( arr, range_detail::is_char_ptr(arr) );
  101. }
  102. }
  103. #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  104. #endif