diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -644,6 +644,11 @@ typedef typename allocator_traits::const_pointer const_pointer; typedef typename allocator_traits::size_type size_type; typedef typename allocator_traits::difference_type difference_type; +#if _LIBCPP_STD_VER > 17 + typedef size_type __remove_return_type; +#else + typedef void __remove_return_type; +#endif typedef typename base::iterator iterator; typedef typename base::const_iterator const_iterator; @@ -819,11 +824,11 @@ void splice_after(const_iterator __p, forward_list& __x, const_iterator __i); void splice_after(const_iterator __p, forward_list& __x, const_iterator __f, const_iterator __l); - size_type remove(const value_type& __v); - template size_type remove_if(_Predicate __pred); + __remove_return_type remove(const value_type& __v); + template __remove_return_type remove_if(_Predicate __pred); _LIBCPP_INLINE_VISIBILITY - size_type unique() {return unique(__equal_to());} - template size_type unique(_BinaryPredicate __binary_pred); + __remove_return_type unique() {return unique(__equal_to());} + template __remove_return_type unique(_BinaryPredicate __binary_pred); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(forward_list&& __x) {merge(__x, __less());} @@ -1496,7 +1501,7 @@ } template -typename forward_list<_Tp, _Alloc>::size_type +typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::remove(const value_type& __v) { forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing @@ -1518,13 +1523,17 @@ else ++__i; } - + +#if _LIBCPP_STD_VER > 17 return __count_removed; +#else + (void)__count_removed; +#endif } template template -typename forward_list<_Tp, _Alloc>::size_type +typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) { forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing @@ -1546,13 +1555,17 @@ else ++__i; } - + +#if _LIBCPP_STD_VER > 17 return __count_removed; +#else + (void)__count_removed; +#endif } template template -typename forward_list<_Tp, _Alloc>::size_type +typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) { forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing @@ -1567,7 +1580,11 @@ __i = __j; } +#if _LIBCPP_STD_VER > 17 return __count_removed; +#else + (void)__count_removed; +#endif } template diff --git a/libcxx/include/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -857,6 +857,11 @@ 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 @@ 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 @@ } 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 @@ -2160,13 +2165,14 @@ else ++__i; } - +#if _LIBCPP_STD_VER > 17 return __deleted_nodes.size(); +#endif } 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 +2192,14 @@ ++__i; } +#if _LIBCPP_STD_VER > 17 return __deleted_nodes.size(); +#endif } 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 @@ -2205,8 +2213,10 @@ __i = __j; } } - + +#if _LIBCPP_STD_VER > 17 return __deleted_nodes.size(); +#endif } template diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp --- a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp @@ -27,6 +27,13 @@ int *i_; }; +#if TEST_STD_VER > 17 + #define ASSERT_CPP20_EQ(expr, num_del) \ + assert((expr) == num_del); +#else + #define ASSERT_CPP20_EQ(expr, num_del) \ + expr; +#endif int main(int, char**) { @@ -37,7 +44,7 @@ const T t2[] = {5, 5, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.remove(0) == 4); + ASSERT_CPP20_EQ(c1.remove(0), 4); assert(c1 == c2); } { @@ -46,7 +53,7 @@ const T t1[] = {0, 0, 0, 0}; C c1(std::begin(t1), std::end(t1)); C c2; - assert(c1.remove(0) == 4); + ASSERT_CPP20_EQ(c1.remove(0), 4); assert(c1 == c2); } { @@ -56,7 +63,7 @@ const T t2[] = {5, 5, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.remove(0) == 0); + ASSERT_CPP20_EQ(c1.remove(0), 0); assert(c1 == c2); } { @@ -64,7 +71,7 @@ typedef std::forward_list C; C c1; C c2; - assert(c1.remove(0) == 0); + ASSERT_CPP20_EQ(c1.remove(0), 0); assert(c1 == c2); } { @@ -74,7 +81,7 @@ const T t2[] = {5, 5, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.remove(0) == 1); + ASSERT_CPP20_EQ(c1.remove(0), 1); assert(c1 == c2); } { // LWG issue #526 @@ -84,7 +91,7 @@ int t2[] = { 2, 3, 5, 8, 11}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.remove(c1.front()) == 2); + ASSERT_CPP20_EQ(c1.remove(c1.front()), 2); assert(c1 == c2); } { @@ -95,7 +102,7 @@ C c; for(int *ip = std::end(t1); ip != std::begin(t1);) c.push_front(S(*--ip)); - assert(c.remove(c.front()) == 3); + ASSERT_CPP20_EQ(c.remove(c.front()), 3); C::const_iterator it = c.begin(); for(int *ip = std::begin(t2); ip != std::end(t2); ++ip, ++it) { assert ( it != c.end()); @@ -111,7 +118,7 @@ const T t2[] = {5, 5, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.remove(0) == 4); + ASSERT_CPP20_EQ(c1.remove(0), 4); assert(c1 == c2); } { @@ -120,7 +127,7 @@ const T t1[] = {0, 0, 0, 0}; C c1(std::begin(t1), std::end(t1)); C c2; - assert(c1.remove(0) == 4); + ASSERT_CPP20_EQ(c1.remove(0), 4); assert(c1 == c2); } { @@ -130,7 +137,7 @@ const T t2[] = {5, 5, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.remove(0) == 0); + ASSERT_CPP20_EQ(c1.remove(0), 0); assert(c1 == c2); } { @@ -138,7 +145,7 @@ typedef std::forward_list> C; C c1; C c2; - assert(c1.remove(0) == 0); + ASSERT_CPP20_EQ(c1.remove(0), 0); assert(c1 == c2); } { @@ -148,7 +155,7 @@ const T t2[] = {5, 5, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.remove(0) == 1); + ASSERT_CPP20_EQ(c1.remove(0), 1); assert(c1 == c2); } #endif diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp --- a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp @@ -19,6 +19,13 @@ #include "min_allocator.h" #include "counting_predicates.hpp" +#if TEST_STD_VER > 17 + #define ASSERT_CPP20_EQ(expr, num_del) \ + assert((expr) == num_del); +#else + #define ASSERT_CPP20_EQ(expr, num_del) \ + expr; +#endif bool g(int i) { @@ -45,7 +52,7 @@ C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 4); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 4); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } @@ -57,7 +64,7 @@ C c1(std::begin(t1), std::end(t1)); C c2; Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 4); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 4); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } @@ -70,7 +77,7 @@ C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 0); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 0); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } @@ -81,7 +88,7 @@ C c1; C c2; Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 0); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 0); assert(c1 == c2); assert(cp.count() == 0); } @@ -94,7 +101,7 @@ C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 1); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 1); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } @@ -123,7 +130,7 @@ C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 4); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 4); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } @@ -135,7 +142,7 @@ C c1(std::begin(t1), std::end(t1)); C c2; Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 4); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 4); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } @@ -148,7 +155,7 @@ C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 0); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 0); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } @@ -159,7 +166,7 @@ C c1; C c2; Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 0); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 0); assert(c1 == c2); assert(cp.count() == 0); } @@ -172,7 +179,7 @@ C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); Predicate cp(g); - assert(c1.remove_if(std::ref(cp)) == 1); + ASSERT_CPP20_EQ(c1.remove_if(std::ref(cp)), 1); assert(c1 == c2); assert(cp.count() == static_cast(std::distance(std::begin(t1), std::end(t1)))); } diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp --- a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp @@ -17,6 +17,14 @@ #include "test_macros.h" #include "min_allocator.h" +#if TEST_STD_VER > 17 + #define ASSERT_CPP20_EQ(expr, num_del) \ + assert((expr) == num_del); +#else + #define ASSERT_CPP20_EQ(expr, num_del) \ + expr; +#endif + int main(int, char**) { { @@ -26,7 +34,7 @@ const T t2[] = {0, 5, 0, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 3); + ASSERT_CPP20_EQ(c1.unique(), 3); assert(c1 == c2); } { @@ -36,7 +44,7 @@ const T t2[] = {0}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 3); + ASSERT_CPP20_EQ(c1.unique(), 3); assert(c1 == c2); } { @@ -46,7 +54,7 @@ const T t2[] = {5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 2); + ASSERT_CPP20_EQ(c1.unique(), 2); assert(c1 == c2); } { @@ -54,7 +62,7 @@ typedef std::forward_list C; C c1; C c2; - assert(c1.unique() == 0); + ASSERT_CPP20_EQ(c1.unique(), 0); assert(c1 == c2); } { @@ -64,7 +72,7 @@ const T t2[] = {5, 0}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 2); + ASSERT_CPP20_EQ(c1.unique(), 2); assert(c1 == c2); } #if TEST_STD_VER >= 11 @@ -75,7 +83,7 @@ const T t2[] = {0, 5, 0, 5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 3); + ASSERT_CPP20_EQ(c1.unique(), 3); assert(c1 == c2); } { @@ -85,7 +93,7 @@ const T t2[] = {0}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 3); + ASSERT_CPP20_EQ(c1.unique(), 3); assert(c1 == c2); } { @@ -95,7 +103,7 @@ const T t2[] = {5}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 2); + ASSERT_CPP20_EQ(c1.unique(), 2); assert(c1 == c2); } { @@ -103,7 +111,7 @@ typedef std::forward_list> C; C c1; C c2; - assert(c1.unique() == 0); + ASSERT_CPP20_EQ(c1.unique(), 0); assert(c1 == c2); } { @@ -113,7 +121,7 @@ const T t2[] = {5, 0}; C c1(std::begin(t1), std::end(t1)); C c2(std::begin(t2), std::end(t2)); - assert(c1.unique() == 2); + ASSERT_CPP20_EQ(c1.unique(), 2); assert(c1 == c2); } #endif 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 --- a/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp @@ -16,6 +16,14 @@ #include "test_macros.h" #include "min_allocator.h" +#if TEST_STD_VER > 17 + #define ASSERT_CPP20_EQ(expr, num_del) \ + assert((expr) == num_del); +#else + #define ASSERT_CPP20_EQ(expr, num_del) \ + expr; +#endif + struct S { S(int i) : i_(new int(i)) {} S(const S &rhs) : i_(new int(*rhs.i_)) {} @@ -37,7 +45,7 @@ int a1[] = {1, 2, 3, 4}; int a2[] = {1, 2, 4}; std::list c(a1, a1 + 4); - assert(c.remove(3) == 1); + ASSERT_CPP20_EQ(c.remove(3), 1); assert(c == std::list(a2, a2 + 3)); } { // LWG issue #526 @@ -53,7 +61,7 @@ std::list c; for (int *ip = a1; ip < a1 + 8; ++ip) c.push_back(S(*ip)); - assert(c.remove(c.front()) == 3); + ASSERT_CPP20_EQ(c.remove(c.front()), 3); std::list::const_iterator it = c.begin(); for (int *ip = a2; ip < a2 + 5; ++ip, ++it) { assert(it != c.end()); @@ -67,7 +75,7 @@ int a1[] = {1, 2, 3, 4}; int a2[] = {1, 2, 4}; List c(a1, a1 + 4, Alloc::create()); - assert(c.remove(3) == 1); + ASSERT_CPP20_EQ(c.remove(3), 1); assert(c == List(a2, a2 + 3, Alloc::create())); } #if TEST_STD_VER >= 11 @@ -75,7 +83,7 @@ int a1[] = {1, 2, 3, 4}; int a2[] = {1, 2, 4}; std::list> c(a1, a1 + 4); - assert(c.remove(3) == 1); + ASSERT_CPP20_EQ(c.remove(3), 1); 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 --- 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 @@ -18,6 +18,14 @@ #include "min_allocator.h" #include "counting_predicates.hpp" +#if TEST_STD_VER > 17 + #define ASSERT_CPP20_EQ(expr, num_del) \ + assert((expr) == num_del); +#else + #define ASSERT_CPP20_EQ(expr, num_del) \ + expr; +#endif + bool even(int i) { return i % 2 == 0; @@ -46,7 +54,7 @@ int a2[] = {3, 4}; std::list c(a1, a1+4); Predicate cp(g); - assert(c.remove_if(std::ref(cp)) == 2); + ASSERT_CPP20_EQ(c.remove_if(std::ref(cp)), 2); assert(c == std::list(a2, a2+2)); assert(cp.count() == 4); } @@ -55,7 +63,7 @@ int a2[] = {1, 3}; std::list c(a1, a1+4); Predicate cp(even); - assert(c.remove_if(std::ref(cp)) == 2); + ASSERT_CPP20_EQ(c.remove_if(std::ref(cp)), 2); assert(c == std::list(a2, a2+2)); assert(cp.count() == 4); } @@ -78,7 +86,7 @@ int a2[] = {3, 4}; std::list> c(a1, a1+4); Predicate cp(g); - assert(c.remove_if(std::ref(cp)) == 2); + ASSERT_CPP20_EQ(c.remove_if(std::ref(cp)), 2); 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 --- a/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp @@ -16,13 +16,21 @@ #include "test_macros.h" #include "min_allocator.h" +#if TEST_STD_VER > 17 + #define ASSERT_CPP20_EQ(expr, num_del) \ + assert((expr) == num_del); +#else + #define ASSERT_CPP20_EQ(expr, num_del) \ + expr; +#endif + 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])); - assert(c.unique() == 5); + ASSERT_CPP20_EQ(c.unique(), 5); assert(c == std::list(a2, a2+4)); } #if TEST_STD_VER >= 11 @@ -30,7 +38,7 @@ 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])); - assert(c.unique() == 5); + ASSERT_CPP20_EQ(c.unique(), 5); assert((c == std::list>(a2, a2+4))); } #endif