begin.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_BEGIN_HPP
  11. #define BOOST_RANGE_BEGIN_HPP
  12. #if defined(_MSC_VER)
  13. # pragma once
  14. #endif
  15. #include <boost/range/config.hpp>
  16. #include <boost/range/iterator.hpp>
  17. #include <boost/config.hpp>
  18. #include <boost/config/workaround.hpp>
  19. namespace boost
  20. {
  21. #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
  22. namespace range_detail
  23. {
  24. #endif
  25. //////////////////////////////////////////////////////////////////////
  26. // primary template
  27. //////////////////////////////////////////////////////////////////////
  28. template< typename C >
  29. BOOST_CONSTEXPR inline BOOST_DEDUCED_TYPENAME range_iterator<C>::type
  30. range_begin( C& c )
  31. {
  32. //
  33. // If you get a compile-error here, it is most likely because
  34. // you have not implemented range_begin() properly in
  35. // the namespace of C
  36. //
  37. return c.begin();
  38. }
  39. //////////////////////////////////////////////////////////////////////
  40. // pair
  41. //////////////////////////////////////////////////////////////////////
  42. template< typename Iterator >
  43. BOOST_CONSTEXPR inline Iterator range_begin( const std::pair<Iterator,Iterator>& p )
  44. {
  45. return p.first;
  46. }
  47. template< typename Iterator >
  48. BOOST_CONSTEXPR inline Iterator range_begin( std::pair<Iterator,Iterator>& p )
  49. {
  50. return p.first;
  51. }
  52. //////////////////////////////////////////////////////////////////////
  53. // array
  54. //////////////////////////////////////////////////////////////////////
  55. //
  56. // May this be discarded? Or is it needed for bad compilers?
  57. //
  58. template< typename T, std::size_t sz >
  59. BOOST_CONSTEXPR inline const T* range_begin( const T (&a)[sz] ) BOOST_NOEXCEPT
  60. {
  61. return a;
  62. }
  63. template< typename T, std::size_t sz >
  64. BOOST_CONSTEXPR inline T* range_begin( T (&a)[sz] ) BOOST_NOEXCEPT
  65. {
  66. return a;
  67. }
  68. #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
  69. } // namespace 'range_detail'
  70. #endif
  71. // Use a ADL namespace barrier to avoid ambiguity with other unqualified
  72. // calls. This is particularly important with C++0x encouraging
  73. // unqualified calls to begin/end.
  74. namespace range_adl_barrier
  75. {
  76. template< class T >
  77. #if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
  78. BOOST_CONSTEXPR
  79. #endif
  80. inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r )
  81. {
  82. #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
  83. using namespace range_detail;
  84. #endif
  85. return range_begin( r );
  86. }
  87. template< class T >
  88. #if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
  89. BOOST_CONSTEXPR
  90. #endif
  91. inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type begin( const T& r )
  92. {
  93. #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
  94. using namespace range_detail;
  95. #endif
  96. return range_begin( r );
  97. }
  98. } // namespace range_adl_barrier
  99. } // namespace boost
  100. namespace boost
  101. {
  102. namespace range_adl_barrier
  103. {
  104. template< class T >
  105. inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type
  106. const_begin( const T& r )
  107. {
  108. return boost::range_adl_barrier::begin( r );
  109. }
  110. } // namespace range_adl_barrier
  111. using namespace range_adl_barrier;
  112. } // namespace boost
  113. #endif