You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

iota.hpp 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. namespace ranges
  22. {
  23. /// \addtogroup group-numerics
  24. /// @{
  25. struct iota_fn
  26. {
  27. template<typename O, typename S, typename T>
  28. auto operator()(O first, S last, T val) const -> CPP_ret(O)( //
  29. requires output_iterator<O, T const &> && sentinel_for<S, O> &&
  30. weakly_incrementable<T>)
  31. {
  32. for(; first != last; ++first, ++val)
  33. *first = detail::as_const(val);
  34. return first;
  35. }
  36. template<typename Rng, typename T>
  37. auto operator()(Rng && rng, T val) const -> CPP_ret(safe_iterator_t<Rng>)( //
  38. requires output_range<Rng, T const &> && weakly_incrementable<T>)
  39. {
  40. return (*this)(begin(rng), end(rng), detail::move(val));
  41. }
  42. };
  43. RANGES_INLINE_VARIABLE(iota_fn, iota)
  44. /// @}
  45. } // namespace ranges
  46. #endif