-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ranges::fill, ranges::fill_n (#41)
* Add ranges::fill, ranges::fill_n * Update algorithm_ranges.cc * Update algorithm_ranges.cc
- Loading branch information
Showing
6 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Created by yonggyulee on 2024. 8. 24. | ||
// | ||
|
||
#ifndef PREVIEW_ALGORITHM_RANGES_FILL_H_ | ||
#define PREVIEW_ALGORITHM_RANGES_FILL_H_ | ||
|
||
#include <type_traits> | ||
|
||
#include "preview/__core/inline_variable.h" | ||
#include "preview/__iterator/iter_value_t.h" | ||
#include "preview/__iterator/output_iterator.h" | ||
#include "preview/__iterator/sentinel_for.h" | ||
#include "preview/__ranges/begin.h" | ||
#include "preview/__ranges/borrowed_iterator_t.h" | ||
#include "preview/__ranges/end.h" | ||
#include "preview/__ranges/output_range.h" | ||
#include "preview/__ranges/range_value_t.h" | ||
#include "preview/__type_traits/conjunction.h" | ||
|
||
namespace preview { | ||
namespace ranges { | ||
namespace detail { | ||
|
||
struct fill_niebloid { | ||
template<typename O, typename S, typename T = iter_value_t<O>, std::enable_if_t<conjunction< | ||
sentinel_for<S, O>, | ||
output_iterator<O, const T&> | ||
>::value, int> = 0> | ||
constexpr O operator()(O first, S last, const T& value) const { | ||
// Must not use std::memset because it may be optimized away by the compiler | ||
while (first != last) | ||
*first++ = value; | ||
return first; | ||
} | ||
|
||
template<typename R, typename T = range_value_t<R>, std::enable_if_t< | ||
output_range<R, const T&> | ||
::value, int> = 0> | ||
constexpr borrowed_iterator_t<R> operator()(R&& r, const T& value) const { | ||
return (*this)(ranges::begin(r), ranges::end(r), value); | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
|
||
PREVIEW_INLINE_VARIABLE constexpr detail::fill_niebloid fill{}; | ||
|
||
} // namespace ranges | ||
} // namespace preview | ||
|
||
#endif // PREVIEW_ALGORITHM_RANGES_FILL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Created by yonggyulee on 2024. 8. 24. | ||
// | ||
|
||
#ifndef PREVIEW_ALGORITHM_RANGES_FILL_N_H_ | ||
#define PREVIEW_ALGORITHM_RANGES_FILL_N_H_ | ||
|
||
#include <type_traits> | ||
|
||
#include "preview/__core/inline_variable.h" | ||
#include "preview/__iterator/iter_difference_t.h" | ||
#include "preview/__iterator/iter_value_t.h" | ||
#include "preview/__iterator/output_iterator.h" | ||
|
||
namespace preview { | ||
namespace ranges { | ||
namespace detail { | ||
|
||
struct fill_n_niebloid { | ||
template<typename O, typename T = iter_value_t<O>, std::enable_if_t< | ||
output_iterator<O, const T&> | ||
::value, int> = 0> | ||
constexpr O operator()(O first, iter_difference_t<O> n, const T& value) const { | ||
while (n != 0) { | ||
*first = value; | ||
++first; | ||
--n; | ||
} | ||
return first; | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
|
||
PREVIEW_INLINE_VARIABLE constexpr detail::fill_n_niebloid fill_n{}; | ||
|
||
} // namespace ranges | ||
} // namespace preview | ||
|
||
#endif // PREVIEW_ALGORITHM_RANGES_FILL_N_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters