1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // template<ForwardIterator Iter, class T>
12 // requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
13 // && HasEqualTo<Iter::value_type, T>
14 // constexpr Iter // constexpr after C++17
15 // remove(Iter first, Iter last, const T& value);
21 #include "test_macros.h"
22 #include "test_iterators.h"
25 TEST_CONSTEXPR
bool test_constexpr() {
26 int ia
[] = {1, 3, 5, 2, 5, 6};
28 auto it
= std::remove(std::begin(ia
), std::end(ia
), 5);
30 return (std::begin(ia
) + std::size(ia
) - 2) == it
// we removed two elements
31 && std::none_of(std::begin(ia
), it
, [](int a
) {return a
== 5; })
40 int ia
[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
41 const unsigned sa
= sizeof(ia
)/sizeof(ia
[0]);
42 Iter r
= std::remove(Iter(ia
), Iter(ia
+sa
), 2);
43 assert(base(r
) == ia
+ sa
-3);
52 #if TEST_STD_VER >= 11
57 const unsigned sa
= 9;
58 std::unique_ptr
<int> ia
[sa
];
59 ia
[0].reset(new int(0));
60 ia
[1].reset(new int(1));
61 ia
[3].reset(new int(3));
62 ia
[4].reset(new int(4));
63 ia
[6].reset(new int(3));
64 ia
[7].reset(new int(4));
65 Iter r
= std::remove(Iter(ia
), Iter(ia
+sa
), std::unique_ptr
<int>());
66 assert(base(r
) == ia
+ sa
-3);
74 #endif // TEST_STD_VER >= 11
78 test
<forward_iterator
<int*> >();
79 test
<bidirectional_iterator
<int*> >();
80 test
<random_access_iterator
<int*> >();
83 #if TEST_STD_VER >= 11
84 test1
<forward_iterator
<std::unique_ptr
<int>*> >();
85 test1
<bidirectional_iterator
<std::unique_ptr
<int>*> >();
86 test1
<random_access_iterator
<std::unique_ptr
<int>*> >();
87 test1
<std::unique_ptr
<int>*>();
88 #endif // TEST_STD_VER >= 11
91 static_assert(test_constexpr());