Iros
 
Loading...
Searching...
No Matches
replace.h
Go to the documentation of this file.
1#pragma once
2
6#include "di/function/equal.h"
7
8namespace di::container {
9namespace detail {
11 template<concepts::InputIterator It, concepts::SentinelFor<It> Sent, typename T, typename U,
12 typename Proj = function::Identity>
15 constexpr auto operator()(It first, Sent last, T const& old_value, U const& new_value, Proj proj = {}) const
16 -> It {
17 for (; first != last; ++first) {
18 if (old_value == function::invoke(proj, *first)) {
19 *first = new_value;
20 }
21 }
22 return first;
23 }
24
25 template<concepts::InputContainer Con, typename T, typename U, typename Proj = function::Identity>
26 requires(concepts::IndirectlyWritable<meta::ContainerIterator<Con>, U const&> &&
27 concepts::IndirectBinaryPredicate<function::Equal, meta::Projected<meta::ContainerIterator<Con>, Proj>,
28 T const*>)
29 constexpr auto operator()(Con&& container, T const& old_value, U const& new_value, Proj proj = {}) const
31 return (*this)(container::begin(container), container::end(container), old_value, new_value, proj);
32 }
33 };
34}
35
36constexpr inline auto replace = detail::ReplaceFunction {};
37}
38
39namespace di {
41}
Definition indirect_binary_predicate.h:12
Definition indirectly_writable.h:8
Definition sequence.h:13
Definition sequence.h:12
constexpr auto replace
Definition replace.h:36
constexpr auto end
Definition end.h:47
constexpr auto begin
Definition begin.h:44
constexpr auto invoke
Definition invoke.h:100
Conditional< concepts::BorrowedContainer< Con >, ContainerIterator< Con >, container::Dangling > BorrowedIterator
Definition borrowed_iterator.h:11
Definition zstring_parser.h:9
constexpr auto proj
Definition proj.h:59