begin.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_DETAIL_BEGIN_HPP
  11. #define BOOST_RANGE_DETAIL_BEGIN_HPP
  12. #include <boost/config.hpp> // BOOST_MSVC
  13. #include <boost/detail/workaround.hpp>
  14. #include <boost/range/iterator.hpp>
  15. #include <boost/range/detail/common.hpp>
  16. #if BOOST_WORKAROUND(BOOST_MSVC, < 1310)
  17. # include <boost/range/value_type.hpp>
  18. #endif
  19. namespace boost
  20. {
  21. namespace range_detail
  22. {
  23. template< typename T >
  24. struct range_begin;
  25. //////////////////////////////////////////////////////////////////////
  26. // default
  27. //////////////////////////////////////////////////////////////////////
  28. template<>
  29. struct range_begin<std_container_>
  30. {
  31. template< typename C >
  32. static BOOST_RANGE_DEDUCED_TYPENAME range_iterator<C>::type fun( C& c )
  33. {
  34. return c.begin();
  35. };
  36. };
  37. //////////////////////////////////////////////////////////////////////
  38. // pair
  39. //////////////////////////////////////////////////////////////////////
  40. template<>
  41. struct range_begin<std_pair_>
  42. {
  43. template< typename P >
  44. static BOOST_RANGE_DEDUCED_TYPENAME range_iterator<P>::type fun( const P& p )
  45. {
  46. return p.first;
  47. }
  48. };
  49. //////////////////////////////////////////////////////////////////////
  50. // array
  51. //////////////////////////////////////////////////////////////////////
  52. template<>
  53. struct range_begin<array_>
  54. {
  55. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
  56. template< typename T, std::size_t sz >
  57. static T* fun( T BOOST_RANGE_ARRAY_REF()[sz] )
  58. {
  59. return boost_range_array;
  60. }
  61. #else
  62. template<typename T>
  63. static BOOST_RANGE_DEDUCED_TYPENAME range_value<T>::type* fun(T& t)
  64. {
  65. return t;
  66. }
  67. #endif
  68. };
  69. } // namespace 'range_detail'
  70. template< typename C >
  71. inline BOOST_RANGE_DEDUCED_TYPENAME range_iterator<C>::type
  72. begin( C& c )
  73. {
  74. return range_detail::range_begin< BOOST_RANGE_DEDUCED_TYPENAME range_detail::range<C>::type >::fun( c );
  75. }
  76. } // namespace 'boost'
  77. #endif