begin.hpp 3.3 KB

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