iota.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2009. 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_ALGORITHM_EXT_IOTA_HPP_INCLUDED
  11. #define BOOST_RANGE_ALGORITHM_EXT_IOTA_HPP_INCLUDED
  12. #include <boost/range/config.hpp>
  13. #include <boost/range/concepts.hpp>
  14. #include <boost/range/iterator.hpp>
  15. #include <boost/range/begin.hpp>
  16. #include <boost/range/end.hpp>
  17. namespace boost
  18. {
  19. namespace range
  20. {
  21. template< class ForwardRange, class Value >
  22. inline ForwardRange& iota( ForwardRange& rng, Value x )
  23. {
  24. BOOST_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  25. typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator_t;
  26. iterator_t last_target = ::boost::end(rng);
  27. for (iterator_t target = ::boost::begin(rng); target != last_target; ++target, ++x)
  28. *target = x;
  29. return rng;
  30. }
  31. template< class ForwardRange, class Value >
  32. inline const ForwardRange& iota( const ForwardRange& rng, Value x )
  33. {
  34. BOOST_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  35. typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type iterator_t;
  36. iterator_t last_target = ::boost::end(rng);
  37. for (iterator_t target = ::boost::begin(rng); target != last_target; ++target, ++x)
  38. *target = x;
  39. return rng;
  40. }
  41. } // namespace range
  42. using range::iota;
  43. } // namespace boost
  44. #endif // include guard