begin.hpp 3.6 KB

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