Skip to content

Commit a4ae870

Browse files
committed
Cleanup indirect_adapter algorithms
1 parent d133c22 commit a4ae870

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

include/cpp-sort/adapters/indirect_adapter.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ namespace cppsort
9898
// Find the element to put in current's place
9999
auto current = start;
100100
auto next_pos = current - first;
101-
auto next = iterators[next_pos];
102101
// We replace all "sorted" iterators with last to make it
103102
// possible to find unsorted iterators between cycles
104-
iterators[next_pos] = last;
103+
auto next = std::exchange(iterators[next_pos], last);
105104

106105
// Process the current cycle
107106
if (next != current) {
@@ -110,8 +109,7 @@ namespace cppsort
110109
*current = iter_move(next);
111110
current = next;
112111
auto next_pos = next - first;
113-
next = iterators[next_pos];
114-
iterators[next_pos] = last;
112+
next = std::exchange(iterators[next_pos], last);
115113
}
116114
*current = std::move(tmp);
117115
}

include/cpp-sort/detail/indiesort.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,22 @@ namespace detail
100100

101101
// Sort the actual elements via the tuple array:
102102
index = 0;
103-
for (auto current_tuple = storage.begin(); current_tuple != storage.end(); ++current_tuple, ++index) {
104-
if (current_tuple->original_index != index) {
105-
auto end_value = iter_move(current_tuple->original_location);
103+
for (auto const& current_tuple : storage) {
104+
if (current_tuple.original_index != index) {
105+
auto end_value = iter_move(current_tuple.original_location);
106106

107107
auto destination_index = index;
108-
auto source_index = current_tuple->original_index;
108+
auto source_index = current_tuple.original_index;
109109

110110
do {
111111
*(storage[destination_index].original_location) = iter_move(storage[source_index].original_location);
112112

113113
destination_index = source_index;
114-
source_index = storage[destination_index].original_index;
115-
storage[destination_index].original_index = destination_index;
114+
source_index = std::exchange(storage[destination_index].original_index, destination_index);
116115
} while (source_index != index);
117116
*(storage[destination_index].original_location) = std::move(end_value);
118117
}
118+
++index;
119119
}
120120

121121
#ifdef __cpp_lib_uncaught_exceptions

0 commit comments

Comments
 (0)