fill.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_ALGORITHM_FILL_HPP
  14. #define RANGES_V3_ALGORITHM_FILL_HPP
  15. #include <range/v3/range_fwd.hpp>
  16. #include <range/v3/iterator/concepts.hpp>
  17. #include <range/v3/range/access.hpp>
  18. #include <range/v3/range/concepts.hpp>
  19. #include <range/v3/range/dangling.hpp>
  20. #include <range/v3/range/traits.hpp>
  21. #include <range/v3/utility/static_const.hpp>
  22. #include <range/v3/detail/prologue.hpp>
  23. namespace ranges
  24. {
  25. /// \addtogroup group-algorithms
  26. /// @{
  27. RANGES_FUNC_BEGIN(fill)
  28. /// \brief function template \c fill
  29. template(typename O, typename S, typename V)(
  30. requires output_iterator<O, V const &> AND sentinel_for<S, O>)
  31. constexpr O RANGES_FUNC(fill)(O first, S last, V const & val) //
  32. {
  33. for(; first != last; ++first)
  34. *first = val;
  35. return first;
  36. }
  37. /// \overload
  38. template(typename Rng, typename V)(
  39. requires output_range<Rng, V const &>)
  40. constexpr borrowed_iterator_t<Rng> RANGES_FUNC(fill)(Rng && rng, V const & val)
  41. {
  42. return (*this)(begin(rng), end(rng), val);
  43. }
  44. RANGES_FUNC_END(fill)
  45. namespace cpp20
  46. {
  47. using ranges::fill;
  48. }
  49. /// @}
  50. } // namespace ranges
  51. #include <range/v3/detail/epilogue.hpp>
  52. #endif