begin.hpp 3.5 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) && (_MSC_VER >= 1200)
  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. namespace boost
  21. {
  22. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
  23. !BOOST_WORKAROUND(__GNUC__, < 3) \
  24. /**/
  25. namespace range_detail
  26. {
  27. #endif
  28. //////////////////////////////////////////////////////////////////////
  29. // primary template
  30. //////////////////////////////////////////////////////////////////////
  31. template< typename C >
  32. 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. inline Iterator range_begin( const std::pair<Iterator,Iterator>& p )
  47. {
  48. return p.first;
  49. }
  50. template< typename Iterator >
  51. 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. inline const T* range_begin( const T (&a)[sz] )
  63. {
  64. return a;
  65. }
  66. template< typename T, std::size_t sz >
  67. inline T* range_begin( T (&a)[sz] )
  68. {
  69. return a;
  70. }
  71. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
  72. !BOOST_WORKAROUND(__GNUC__, < 3) \
  73. /**/
  74. } // namespace 'range_detail'
  75. #endif
  76. // Use a ADL namespace barrier to avoid ambiguity with other unqualified
  77. // calls. This is particularly important with C++0x encouraging
  78. // unqualified calls to begin/end.
  79. namespace range_adl_barrier
  80. {
  81. template< class T >
  82. inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r )
  83. {
  84. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
  85. !BOOST_WORKAROUND(__GNUC__, < 3) \
  86. /**/
  87. using namespace range_detail;
  88. #endif
  89. return range_begin( r );
  90. }
  91. template< class T >
  92. inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type begin( const T& r )
  93. {
  94. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
  95. !BOOST_WORKAROUND(__GNUC__, < 3) \
  96. /**/
  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