@@ -12,6 +12,8 @@ export module containers.algorithms.uninitialized;
12
12
import containers.algorithms.destroy_range;
13
13
import containers.algorithms.copy_or_relocate_from;
14
14
import containers.begin_end;
15
+ import containers.bidirectional_iterator;
16
+ import containers.bidirectional_range;
15
17
import containers.data;
16
18
import containers.iter_difference_t ;
17
19
import containers.iter_value_t ;
@@ -91,22 +93,37 @@ export constexpr auto uninitialized_copy_no_overlap = []<range InputRange, itera
91
93
}
92
94
};
93
95
96
+ constexpr auto relocate_from (auto & it) {
97
+ return [&] {
98
+ if constexpr (std::is_reference_v<decltype (*it)>) {
99
+ return bounded::relocate (*it);
100
+ } else {
101
+ return *it;
102
+ }
103
+ };
104
+ }
105
+
94
106
export constexpr auto uninitialized_relocate = [](range auto && input, iterator auto output) {
95
107
auto const last = containers::end (OPERATORS_FORWARD (input));
96
108
for (auto it = containers::begin (OPERATORS_FORWARD (input)); it != last; ++it) {
97
- bounded::construct_at (*output, [&] {
98
- if constexpr (std::is_reference_v<decltype (*it)>) {
99
- return bounded::relocate (*it);
100
- } else {
101
- return *it;
102
- }
103
- });
109
+ bounded::construct_at (*output, ::containers::relocate_from (it));
104
110
++output;
105
111
}
106
112
return output;
107
113
};
108
114
109
- export constexpr auto uninitialized_relocate_no_overlap = []<range InputRange, iterator OutputIterator>(InputRange && source, OutputIterator out) {
115
+ export constexpr auto uninitialized_relocate_backward = [](bidirectional_range auto && input, bidirectional_iterator auto output_last) {
116
+ auto const first = containers::begin (OPERATORS_FORWARD (input));
117
+ auto last = containers::end (OPERATORS_FORWARD (input));
118
+ while (last != first) {
119
+ --last;
120
+ --output_last;
121
+ bounded::construct_at (*output_last, ::containers::relocate_from (last));
122
+ }
123
+ return output_last;
124
+ };
125
+
126
+ export constexpr auto uninitialized_relocate_no_overlap = []<range InputRange, iterator OutputIterator>(InputRange && source, OutputIterator out) -> OutputIterator {
110
127
if constexpr (memcpyable<InputRange, OutputIterator>) {
111
128
auto result = uninitialized_copy_no_overlap (source, out);
112
129
::containers::destroy_range (source);
0 commit comments