[gcc(refs/users/ppalka/heads/libstdcxx-constrained-algos)] Make ranges::remove_copy and ranges::remove_copy_if unmoveable-iterator-safe
Patrick Palka
ppalka@gcc.gnu.org
Wed Jan 22 22:34:00 GMT 2020
https://gcc.gnu.org/g:6532cfccb2c2c3d5bccadb69f0cc1f619902f5b2
commit 6532cfccb2c2c3d5bccadb69f0cc1f619902f5b2
Author: Patrick Palka <ppalka@redhat.com>
Date: Wed Jan 22 17:30:42 2020 -0500
Make ranges::remove_copy and ranges::remove_copy_if unmoveable-iterator-safe
Diff:
---
libstdc++-v3/include/bits/ranges_algo.h | 9 +++++----
libstdc++-v3/testsuite/25_algorithms/remove_copy/constrained.cc | 8 +++++---
.../testsuite/25_algorithms/remove_copy_if/constrained.cc | 8 +++++---
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h
index 8ea616b..466a2d8 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -1356,7 +1356,7 @@ namespace ranges
*__result = *__first;
++__result;
}
- return {__first, __result};
+ return {std::move(__first), std::move(__result)};
}
template<input_range _Range, weakly_incrementable _Out,
@@ -1368,7 +1368,7 @@ namespace ranges
_Pred __pred, _Proj __proj = {})
{
return ranges::remove_copy_if(ranges::begin(__r), ranges::end(__r),
- __result,
+ std::move(__result),
std::move(__pred), std::move(__proj));
}
@@ -1391,7 +1391,7 @@ namespace ranges
*__result = *__first;
++__result;
}
- return {__first, __result};
+ return {std::move(__first), std::move(__result)};
}
template<input_range _Range, weakly_incrementable _Out,
@@ -1405,7 +1405,8 @@ namespace ranges
const _Tp& __value, _Proj __proj = {})
{
return ranges::remove_copy(ranges::begin(__r), ranges::end(__r),
- __result, __value, std::move(__proj));
+ std::move(__result), __value,
+ std::move(__proj));
}
diff --git a/libstdc++-v3/testsuite/25_algorithms/remove_copy/constrained.cc b/libstdc++-v3/testsuite/25_algorithms/remove_copy/constrained.cc
index 2303293..0cf65a7 100644
--- a/libstdc++-v3/testsuite/25_algorithms/remove_copy/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/remove_copy/constrained.cc
@@ -25,6 +25,7 @@
using __gnu_test::test_container;
using __gnu_test::test_range;
using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
using __gnu_test::forward_iterator_wrapper;
namespace ranges = std::ranges;
@@ -74,11 +75,12 @@ test01()
{
X x[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
X y[4];
- X z[4] = { {6}, {8}, {10}, {11} };
- test_range<X, forward_iterator_wrapper> cx(x), cy(y), cz(z);
+ const X z[4] = { {6}, {8}, {10}, {11} };
+ test_range<X, input_iterator_wrapper> cx(x);
+ test_range<X, output_iterator_wrapper> cy(y);
auto [in, out] = ranges::remove_copy(cx, cy.begin(), 2, &X::i);
VERIFY( in == cx.end() && out == cy.end() );
- VERIFY( ranges::equal(cy, cz) );
+ VERIFY( ranges::equal(y, z) );
}
}
diff --git a/libstdc++-v3/testsuite/25_algorithms/remove_copy_if/constrained.cc b/libstdc++-v3/testsuite/25_algorithms/remove_copy_if/constrained.cc
index b38cf1c..b7c239f 100644
--- a/libstdc++-v3/testsuite/25_algorithms/remove_copy_if/constrained.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/remove_copy_if/constrained.cc
@@ -25,6 +25,7 @@
using __gnu_test::test_container;
using __gnu_test::test_range;
using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
using __gnu_test::forward_iterator_wrapper;
namespace ranges = std::ranges;
@@ -77,11 +78,12 @@ test01()
{
X x[6] = { {2}, {2}, {6}, {8}, {10}, {11} };
X y[4];
- X z[4] = { {6}, {8}, {10}, {11} };
- test_range<X, forward_iterator_wrapper> cx(x), cy(y), cz(z);
+ const X z[4] = { {6}, {8}, {10}, {11} };
+ test_range<X, input_iterator_wrapper> cx(x);
+ test_range<X, output_iterator_wrapper> cy(y);
auto [in, out] = ranges::remove_copy_if(cx, cy.begin(), is_two_p, &X::i);
VERIFY( in == cx.end() && out == cy.end() );
- VERIFY( ranges::equal(cy, cz) );
+ VERIFY( ranges::equal(y, z) );
}
}
More information about the Libstdc++-cvs
mailing list