begin.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. template< class T >
  77. inline BOOST_DEDUCED_TYPENAME range_iterator<T>::type begin( T& r )
  78. {
  79. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
  80. !BOOST_WORKAROUND(__GNUC__, < 3) \
  81. /**/
  82. using namespace range_detail;
  83. #endif
  84. return range_begin( r );
  85. }
  86. template< class T >
  87. inline BOOST_DEDUCED_TYPENAME range_iterator<const T>::type begin( const T& r )
  88. {
  89. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) && \
  90. !BOOST_WORKAROUND(__GNUC__, < 3) \
  91. /**/
  92. using namespace range_detail;
  93. #endif
  94. return range_begin( r );
  95. }
  96. } // namespace boost
  97. #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  98. namespace boost
  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::begin( r );
  105. }
  106. }
  107. #endif