counting_range.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright Neil Groves 2010. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_COUNTING_RANGE_HPP_INCLUDED
  10. #define BOOST_RANGE_COUNTING_RANGE_HPP_INCLUDED
  11. #include <boost/config.hpp>
  12. #if BOOST_MSVC >= 1400
  13. #pragma warning(push)
  14. #pragma warning(disable : 4244)
  15. #endif
  16. #include <boost/range/iterator_range_core.hpp>
  17. #include <boost/range/value_type.hpp>
  18. #include <boost/range/iterator.hpp>
  19. #include <boost/iterator/counting_iterator.hpp>
  20. namespace boost
  21. {
  22. template<class Value>
  23. inline iterator_range<counting_iterator<Value> >
  24. counting_range(Value first, Value last)
  25. {
  26. typedef counting_iterator<Value> counting_iterator_t;
  27. typedef iterator_range<counting_iterator_t> result_t;
  28. return result_t(counting_iterator_t(first),
  29. counting_iterator_t(last));
  30. }
  31. template<class Range>
  32. inline iterator_range<
  33. counting_iterator<
  34. BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type
  35. >
  36. >
  37. counting_range(const Range& rng)
  38. {
  39. typedef counting_iterator<
  40. BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type
  41. > counting_iterator_t;
  42. typedef iterator_range<counting_iterator_t> result_t;
  43. return result_t(counting_iterator_t(boost::begin(rng)),
  44. counting_iterator_t(boost::end(rng)));
  45. }
  46. template<class Range>
  47. inline iterator_range<
  48. counting_iterator<
  49. BOOST_DEDUCED_TYPENAME range_iterator<Range>::type
  50. >
  51. >
  52. counting_range(Range& rng)
  53. {
  54. typedef counting_iterator<
  55. BOOST_DEDUCED_TYPENAME range_iterator<Range>::type
  56. > counting_iterator_t;
  57. typedef iterator_range<counting_iterator_t> result_t;
  58. return result_t(counting_iterator_t(boost::begin(rng)),
  59. counting_iterator_t(boost::end(rng)));
  60. }
  61. } // namespace boost
  62. #if BOOST_MSVC >= 1400
  63. #pragma warning(pop)
  64. #endif
  65. #endif // include guard