iota.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #ifndef RANGES_V3_NUMERIC_IOTA_HPP
  14. #define RANGES_V3_NUMERIC_IOTA_HPP
  15. #include <range/v3/iterator/concepts.hpp>
  16. #include <range/v3/range/access.hpp>
  17. #include <range/v3/range/concepts.hpp>
  18. #include <range/v3/range/dangling.hpp>
  19. #include <range/v3/range/traits.hpp>
  20. #include <range/v3/utility/static_const.hpp>
  21. #include <range/v3/detail/prologue.hpp>
  22. namespace ranges
  23. {
  24. /// \addtogroup group-numerics
  25. /// @{
  26. struct iota_fn
  27. {
  28. template(typename O, typename S, typename T)(
  29. requires output_iterator<O, T const &> AND sentinel_for<S, O> AND
  30. weakly_incrementable<T>)
  31. O operator()(O first, S last, T val) const
  32. {
  33. for(; first != last; ++first, ++val)
  34. *first = detail::as_const(val);
  35. return first;
  36. }
  37. template(typename Rng, typename T)(
  38. requires output_range<Rng, T const &> AND weakly_incrementable<T>)
  39. borrowed_iterator_t<Rng> operator()(Rng && rng, T val) const //
  40. {
  41. return (*this)(begin(rng), end(rng), detail::move(val));
  42. }
  43. };
  44. RANGES_INLINE_VARIABLE(iota_fn, iota)
  45. /// @}
  46. } // namespace ranges
  47. #include <range/v3/detail/epilogue.hpp>
  48. #endif