1
1
/*
2
- * Copyright (c) 2015-2022 Morwenn
2
+ * Copyright (c) 2015-2025 Morwenn
3
3
* SPDX-License-Identifier: MIT
4
4
*/
5
5
#ifndef CPPSORT_ADAPTERS_INDIRECT_ADAPTER_H_
12
12
#include < iterator>
13
13
#include < type_traits>
14
14
#include < utility>
15
- #include < vector>
16
15
#include < cpp-sort/sorter_facade.h>
17
16
#include < cpp-sort/sorter_traits.h>
18
17
#include < cpp-sort/utility/adapter_storage.h>
@@ -92,8 +91,6 @@ namespace cppsort
92
91
// //////////////////////////////////////////////////////////
93
92
// Move the values according the iterator's positions
94
93
95
- std::vector<bool > sorted (last - first, false );
96
-
97
94
// Element where the current cycle starts
98
95
auto start = first;
99
96
@@ -102,7 +99,9 @@ namespace cppsort
102
99
auto current = start;
103
100
auto next_pos = current - first;
104
101
auto next = iterators[next_pos];
105
- sorted[next_pos] = true ;
102
+ // We replace all "sorted" iterators with last to make it
103
+ // possible to find unsorted iterators between cycles
104
+ iterators[next_pos] = last;
106
105
107
106
// Process the current cycle
108
107
if (next != current) {
@@ -112,15 +111,15 @@ namespace cppsort
112
111
current = next;
113
112
auto next_pos = next - first;
114
113
next = iterators[next_pos];
115
- sorted [next_pos] = true ;
114
+ iterators [next_pos] = last ;
116
115
}
117
116
*current = std::move (tmp);
118
117
}
119
118
120
119
// Find the next cycle
121
120
do {
122
121
++start;
123
- } while (start != last && sorted [start - first]);
122
+ } while (start != last && iterators [start - first] == last );
124
123
125
124
}
126
125
#ifdef __cpp_lib_uncaught_exceptions
0 commit comments