begin.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. namespace boost
  17. {
  18. namespace range_detail
  19. {
  20. template< typename T >
  21. struct range_begin;
  22. //////////////////////////////////////////////////////////////////////
  23. // default
  24. //////////////////////////////////////////////////////////////////////
  25. template<>
  26. struct range_begin<std_container_>
  27. {
  28. template< typename C >
  29. BOOST_CONSTEXPR static BOOST_RANGE_DEDUCED_TYPENAME range_iterator<C>::type fun( C& c )
  30. {
  31. return c.begin();
  32. };
  33. };
  34. //////////////////////////////////////////////////////////////////////
  35. // pair
  36. //////////////////////////////////////////////////////////////////////
  37. template<>
  38. struct range_begin<std_pair_>
  39. {
  40. template< typename P >
  41. BOOST_CONSTEXPR static BOOST_RANGE_DEDUCED_TYPENAME range_iterator<P>::type fun( const P& p )
  42. {
  43. return p.first;
  44. }
  45. };
  46. //////////////////////////////////////////////////////////////////////
  47. // array
  48. //////////////////////////////////////////////////////////////////////
  49. template<>
  50. struct range_begin<array_>
  51. {
  52. template<typename T>
  53. BOOST_CONSTEXPR static BOOST_RANGE_DEDUCED_TYPENAME range_value<T>::type* fun(T& t)
  54. {
  55. return t;
  56. }
  57. };
  58. } // namespace 'range_detail'
  59. namespace range_adl_barrier
  60. {
  61. template< typename C >
  62. BOOST_CONSTEXPR inline BOOST_RANGE_DEDUCED_TYPENAME range_iterator<C>::type
  63. begin( C& c )
  64. {
  65. return range_detail::range_begin< BOOST_RANGE_DEDUCED_TYPENAME range_detail::range<C>::type >::fun( c );
  66. }
  67. }
  68. } // namespace 'boost'
  69. #endif