mirror of
https://github.com/gcc-mirror/gcc.git
synced 2026-05-06 23:14:49 +02:00
libstdc++: Use ranges::iter_move in ranges::unique [PR120789]
PR libstdc++/120789 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__unique_fn::operator()): Use ranges::iter_move(iter) instead of std::move(*iter). * testsuite/25_algorithms/unique/120789.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
This commit is contained in:
@@ -1454,7 +1454,7 @@ namespace ranges
|
||||
if (!std::__invoke(__comp,
|
||||
std::__invoke(__proj, *__dest),
|
||||
std::__invoke(__proj, *__first)))
|
||||
*++__dest = std::move(*__first);
|
||||
*++__dest = ranges::iter_move(__first);
|
||||
return {++__dest, __first};
|
||||
}
|
||||
|
||||
|
||||
36
libstdc++-v3/testsuite/25_algorithms/unique/120789.cc
Normal file
36
libstdc++-v3/testsuite/25_algorithms/unique/120789.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
// PR libstdc++/120789 - ranges::unique should use ranges::iter_move
|
||||
// { dg-do compile { target c++20 } }
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
struct A
|
||||
{
|
||||
bool operator==(const A&) const;
|
||||
};
|
||||
|
||||
struct B
|
||||
{
|
||||
B(B&&) = delete;
|
||||
B& operator=(const A&) const;
|
||||
|
||||
operator A() const;
|
||||
bool operator==(const B&) const;
|
||||
};
|
||||
|
||||
struct I
|
||||
{
|
||||
using value_type = A;
|
||||
using difference_type = int;
|
||||
B operator*() const;
|
||||
I& operator++();
|
||||
I operator++(int);
|
||||
bool operator==(const I&) const;
|
||||
friend A iter_move(const I&);
|
||||
};
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::ranges::subrange<I, I> r;
|
||||
auto [begin, end] = std::ranges::unique(r);
|
||||
}
|
||||
Reference in New Issue
Block a user