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 // void remove(const value_type& value); // pre-c++20
12 // size_type remove(const value_type& value); // c++20 and later
17 #include "test_macros.h"
18 #include "min_allocator.h"
21 S(int i
) : i_(new int(i
)) {}
22 S(const S
&rhs
) : i_(new int(*rhs
.i_
)) {}
23 S
&operator=(const S
&rhs
) {
31 bool operator==(const S
&rhs
) const { return *i_
== *rhs
.i_
; }
32 int get() const { return *i_
; }
36 int main(int, char**) {
38 int a1
[] = {1, 2, 3, 4};
40 typedef std::list
<int> L
;
43 assert(c
.remove(3) == 1);
44 ASSERT_SAME_TYPE(L::size_type
, decltype(c
.remove(3)));
46 ASSERT_SAME_TYPE(void, decltype(c
.remove(3)));
50 assert(c
== std::list
<int>(a2
, a2
+ 3));
53 int a1
[] = {1, 2, 1, 3, 5, 8, 11};
54 int a2
[] = {2, 3, 5, 8, 11};
55 std::list
<int> c(a1
, a1
+ 7);
57 assert(c
== std::list
<int>(a2
, a2
+ 5));
60 int a1
[] = {1, 2, 1, 3, 5, 8, 11, 1};
61 int a2
[] = {2, 3, 5, 8, 11};
63 for (int *ip
= a1
; ip
< a1
+ 8; ++ip
)
66 assert(c
.remove(c
.front()) == 3);
70 std::list
<S
>::const_iterator it
= c
.begin();
71 for (int *ip
= a2
; ip
< a2
+ 5; ++ip
, ++it
) {
72 assert(it
!= c
.end());
73 assert(*ip
== it
->get());
75 assert(it
== c
.end());
78 typedef no_default_allocator
<int> Alloc
;
79 typedef std::list
<int, Alloc
> List
;
80 int a1
[] = {1, 2, 3, 4};
82 List
c(a1
, a1
+ 4, Alloc::create());
84 assert(c
.remove(3) == 1);
88 assert(c
== List(a2
, a2
+ 3, Alloc::create()));
90 #if TEST_STD_VER >= 11
92 int a1
[] = {1, 2, 3, 4};
94 std::list
<int, min_allocator
<int>> c(a1
, a1
+ 4);
96 assert(c
.remove(3) == 1);
100 assert((c
== std::list
<int, min_allocator
<int>>(a2
, a2
+ 3)));