From 1ab3fe8a7a6537f882bbb2dac72c479d05eb8c49 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 6 Jul 2019 06:10:03 +0000 Subject: Make list::remove/remove_if/unique all return void before C++20; undoes that bit of D58332. Thanks to Mikhail Maltsev for pointing this out llvm-svn: 365261 --- libcxx/include/list | 33 +++++++++++++--------- .../sequences/list/list.ops/remove.pass.cpp | 27 ++++++++++++++++-- .../sequences/list/list.ops/remove_if.pass.cpp | 30 +++++++++++++++----- .../sequences/list/list.ops/unique.pass.cpp | 16 +++++++++-- .../sequences/list/list.ops/unique_pred.pass.cpp | 30 +++++++++++++++----- 5 files changed, 103 insertions(+), 33 deletions(-) (limited to 'libcxx') diff --git a/libcxx/include/list b/libcxx/include/list index cbc165b..2e80b2f 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -129,11 +129,11 @@ public: void splice(const_iterator position, list&& x, const_iterator first, const_iterator last); - size_type remove(const value_type& value); - template size_type remove_if(Pred pred); - size_type unique(); + size_type remove(const value_type& value); // void before C++20 + template size_type remove_if(Pred pred); // void before C++20 + size_type unique(); // void before C++20 template - size_type unique(BinaryPredicate binary_pred); + size_type unique(BinaryPredicate binary_pred); // void before C++20 void merge(list& x); void merge(list&& x); template @@ -857,6 +857,11 @@ public: typedef typename base::const_iterator const_iterator; typedef _VSTD::reverse_iterator reverse_iterator; typedef _VSTD::reverse_iterator const_reverse_iterator; +#if _LIBCPP_STD_VER > 17 + typedef size_type __remove_return_type; +#else + typedef void __remove_return_type; +#endif _LIBCPP_INLINE_VISIBILITY list() @@ -1070,12 +1075,12 @@ public: void splice(const_iterator __p, list& __c, const_iterator __i); void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); - size_type remove(const value_type& __x); - template size_type remove_if(_Pred __pred); + __remove_return_type remove(const value_type& __x); + template __remove_return_type remove_if(_Pred __pred); _LIBCPP_INLINE_VISIBILITY - size_type unique() { return unique(__equal_to()); } + __remove_return_type unique() { return unique(__equal_to()); } template - size_type unique(_BinaryPred __binary_pred); + __remove_return_type unique(_BinaryPred __binary_pred); _LIBCPP_INLINE_VISIBILITY void merge(list& __c); #ifndef _LIBCPP_CXX03_LANG @@ -2141,7 +2146,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con } template -typename list<_Tp, _Alloc>::size_type +typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove(const value_type& __x) { list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing @@ -2161,12 +2166,12 @@ list<_Tp, _Alloc>::remove(const value_type& __x) ++__i; } - return __deleted_nodes.size(); + return (__remove_return_type) __deleted_nodes.size(); } template template -typename list<_Tp, _Alloc>::size_type +typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove_if(_Pred __pred) { list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing @@ -2186,12 +2191,12 @@ list<_Tp, _Alloc>::remove_if(_Pred __pred) ++__i; } - return __deleted_nodes.size(); + return (__remove_return_type) __deleted_nodes.size(); } template template -typename list<_Tp, _Alloc>::size_type +typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) { list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing @@ -2206,7 +2211,7 @@ list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) } } - return __deleted_nodes.size(); + return (__remove_return_type) __deleted_nodes.size(); } template diff --git a/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp index 19a8817..8c9a062 100644 --- a/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp @@ -8,7 +8,8 @@ // -// void remove(const value_type& value); +// void remove(const value_type& value); // pre-c++20 +// size_type remove(const value_type& value); // c++20 and later #include #include @@ -36,8 +37,16 @@ int main(int, char**) { { int a1[] = {1, 2, 3, 4}; int a2[] = {1, 2, 4}; - std::list c(a1, a1 + 4); + typedef std::list L; + L c(a1, a1 + 4); +#if TEST_STD_VER > 17 assert(c.remove(3) == 1); + ASSERT_SAME_TYPE(L::size_type, decltype(c.remove(3))); +#else + ASSERT_SAME_TYPE(void, decltype(c.remove(3))); + c.remove(3); +#endif + assert(c == std::list(a2, a2 + 3)); } { // LWG issue #526 @@ -53,7 +62,11 @@ int main(int, char**) { std::list c; for (int *ip = a1; ip < a1 + 8; ++ip) c.push_back(S(*ip)); +#if TEST_STD_VER > 17 assert(c.remove(c.front()) == 3); +#else + c.remove(c.front()); +#endif std::list::const_iterator it = c.begin(); for (int *ip = a2; ip < a2 + 5; ++ip, ++it) { assert(it != c.end()); @@ -67,7 +80,11 @@ int main(int, char**) { int a1[] = {1, 2, 3, 4}; int a2[] = {1, 2, 4}; List c(a1, a1 + 4, Alloc::create()); - assert(c.remove(3) == 1); +#if TEST_STD_VER > 17 + assert(c.remove(3) == 1); +#else + c.remove(3); +#endif assert(c == List(a2, a2 + 3, Alloc::create())); } #if TEST_STD_VER >= 11 @@ -75,7 +92,11 @@ int main(int, char**) { int a1[] = {1, 2, 3, 4}; int a2[] = {1, 2, 4}; std::list> c(a1, a1 + 4); +#if TEST_STD_VER > 17 assert(c.remove(3) == 1); +#else + c.remove(3); +#endif assert((c == std::list>(a2, a2 + 3))); } #endif diff --git a/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp index d78f7db..0944e68 100644 --- a/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp @@ -8,7 +8,8 @@ // -// template void remove_if(Pred pred); +// template void remove_if(Pred pred); // before C++20 +// template size_type remove_if(Pred pred); // c++20 and later #include #include @@ -28,10 +29,10 @@ bool g(int i) return i < 3; } -struct PredLWG529 { - PredLWG529 (int i) : i_(i) {}; - ~PredLWG529() { i_ = -32767; } - bool operator() (const PredLWG529 &p) const { return p.i_ == i_; } +struct PredLWG526 { + PredLWG526 (int i) : i_(i) {}; + ~PredLWG526() { i_ = -32767; } + bool operator() (const PredLWG526 &p) const { return p.i_ == i_; } bool operator==(int i) const { return i == i_;} int i_; @@ -44,9 +45,16 @@ int main(int, char**) { int a1[] = {1, 2, 3, 4}; int a2[] = {3, 4}; - std::list c(a1, a1+4); + typedef std::list L; + L c(a1, a1+4); Predicate cp(g); +#if TEST_STD_VER > 17 + ASSERT_SAME_TYPE(L::size_type, decltype(c.remove_if(std::ref(cp)))); assert(c.remove_if(std::ref(cp)) == 2); +#else + ASSERT_SAME_TYPE(void, decltype(c.remove_if(std::ref(cp)))); + c.remove_if(std::ref(cp)); +#endif assert(c == std::list(a2, a2+2)); assert(cp.count() == 4); } @@ -55,14 +63,18 @@ int main(int, char**) int a2[] = {1, 3}; std::list c(a1, a1+4); Predicate cp(even); +#if TEST_STD_VER > 17 assert(c.remove_if(std::ref(cp)) == 2); +#else + c.remove_if(std::ref(cp)); +#endif assert(c == std::list(a2, a2+2)); assert(cp.count() == 4); } { // LWG issue #526 int a1[] = {1, 2, 1, 3, 5, 8, 11}; int a2[] = {2, 3, 5, 8, 11}; - std::list c(a1, a1 + 7); + std::list c(a1, a1 + 7); c.remove_if(std::ref(c.front())); assert(c.size() == 5); for (size_t i = 0; i < c.size(); ++i) @@ -78,7 +90,11 @@ int main(int, char**) int a2[] = {3, 4}; std::list> c(a1, a1+4); Predicate cp(g); +#if TEST_STD_VER > 17 assert(c.remove_if(std::ref(cp)) == 2); +#else + c.remove_if(std::ref(cp)); +#endif assert((c == std::list>(a2, a2+2))); assert(cp.count() == 4); } diff --git a/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp index dc80d03..85c4ec5 100644 --- a/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp @@ -8,7 +8,8 @@ // -// void unique(); +// void unique(); // before C++20 +// size_type unique(); // C++20 and later #include #include @@ -21,8 +22,15 @@ int main(int, char**) { int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; int a2[] = {2, 1, 4, 3}; - std::list c(a1, a1+sizeof(a1)/sizeof(a1[0])); + typedef std::list L; + L c(a1, a1+sizeof(a1)/sizeof(a1[0])); +#if TEST_STD_VER > 17 + ASSERT_SAME_TYPE(L::size_type, decltype(c.unique())); assert(c.unique() == 5); +#else + ASSERT_SAME_TYPE(void, decltype(c.unique())); + c.unique(); +#endif assert(c == std::list(a2, a2+4)); } #if TEST_STD_VER >= 11 @@ -30,7 +38,11 @@ int main(int, char**) int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; int a2[] = {2, 1, 4, 3}; std::list> c(a1, a1+sizeof(a1)/sizeof(a1[0])); +#if TEST_STD_VER > 17 assert(c.unique() == 5); +#else + c.unique(); +#endif assert((c == std::list>(a2, a2+4))); } #endif diff --git a/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp index 6338324..75f8c7b 100644 --- a/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp @@ -8,7 +8,8 @@ // -// template void unique(BinaryPred pred); +// template void unique(BinaryPred pred); // before C++20 +// template size_type unique(BinaryPred pred); // C++20 and later #include #include @@ -21,10 +22,10 @@ bool g(int x, int y) return x == y; } -struct PredLWG529 { - PredLWG529 (int i) : i_(i) {}; - ~PredLWG529() { i_ = -32767; } - bool operator() (const PredLWG529 &lhs, const PredLWG529 &rhs) const { return lhs.i_ == rhs.i_; } +struct PredLWG526 { + PredLWG526 (int i) : i_(i) {}; + ~PredLWG526() { i_ = -32767; } + bool operator() (const PredLWG526 &lhs, const PredLWG526 &rhs) const { return lhs.i_ == rhs.i_; } bool operator==(int i) const { return i == i_;} int i_; @@ -35,16 +36,27 @@ int main(int, char**) { int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; int a2[] = {2, 1, 4, 3}; - std::list c(a1, a1+sizeof(a1)/sizeof(a1[0])); + typedef std::list L; + L c(a1, a1+sizeof(a1)/sizeof(a1[0])); +#if TEST_STD_VER > 17 + ASSERT_SAME_TYPE(L::size_type, decltype(c.unique(g))); + assert(c.unique(g) == 5); +#else + ASSERT_SAME_TYPE(void, decltype(c.unique(g))); c.unique(g); +#endif assert(c == std::list(a2, a2+4)); } { // LWG issue #526 int a1[] = {1, 1, 1, 2, 3, 5, 5, 2, 11}; int a2[] = {1, 2, 3, 5, 2, 11}; - std::list c(a1, a1 + 9); + std::list c(a1, a1 + 9); +#if TEST_STD_VER > 17 + assert(c.unique(std::ref(c.front())) == 3); +#else c.unique(std::ref(c.front())); +#endif assert(c.size() == 6); for (size_t i = 0; i < c.size(); ++i) { @@ -58,7 +70,11 @@ int main(int, char**) int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; int a2[] = {2, 1, 4, 3}; std::list> c(a1, a1+sizeof(a1)/sizeof(a1[0])); +#if TEST_STD_VER > 17 + assert(c.unique(g) == 5); +#else c.unique(g); +#endif assert((c == std::list>(a2, a2+4))); } #endif -- cgit v1.1