Skip to content

Commit c6c1f26

Browse files
committed
Use reference_wrapper in compress_coords
1 parent 94525b6 commit c6c1f26

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

cp-algo/util/compress_coords.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
#include <algorithm>
44
#include <vector>
55
namespace cp_algo {
6+
// coords is a range of reference_wrapper<T>
67
std::vector<int> compress_coords(auto &coords) {
7-
static_assert(std::is_pointer_v<std::ranges::range_value_t<decltype(coords)>>);
88
std::vector<int> original;
99
original.reserve(size(coords));
10-
std::ranges::sort(coords, {}, [](int* x) {return *x;});
10+
std::ranges::sort(coords);
1111
int idx = -1, prev = -1;
12-
for(auto x: coords) {
13-
if(*x != prev) {
12+
for(auto &x: coords) {
13+
if(x != prev) {
1414
idx++;
15-
prev = *x;
16-
original.push_back(*x);
15+
prev = x;
16+
original.push_back(x);
1717
}
18-
*x = idx;
18+
x.get() = idx;
1919
}
2020
return original;
2121
}

verify/structures/fenwick/ordered_set.test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ void solve() {
1212
int n, q;
1313
cin >> n >> q;
1414
vector a(n, 0);
15-
vector<int*> coords;
15+
vector<reference_wrapper<int>> coords;
1616
for(auto &it: a) {
1717
cin >> it;
18-
coords.push_back(&it);
18+
coords.push_back(ref(it));
1919
}
2020
vector queries(q, pair{0, 0});
2121
for(auto &[t, x]: queries) {
2222
cin >> t >> x;
2323
if(t != 2) {
24-
coords.push_back(&x);
24+
coords.push_back(ref(x));
2525
}
2626
}
2727
auto values = cp_algo::compress_coords(coords);

0 commit comments

Comments
 (0)