1 //===----------------------------------------------------------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <list> 10 11 // void remove(const value_type& value); 12 13 #include <list> 14 #include <cassert> 15 16 #include "test_macros.h" 17 #include "min_allocator.h" 18 19 struct S { 20 S(int i) : i_(new int(i)) {} 21 S(const S &rhs) : i_(new int(*rhs.i_)) {} 22 S &operator=(const S &rhs) { 23 *i_ = *rhs.i_; 24 return *this; 25 } 26 ~S() { 27 delete i_; 28 i_ = NULL; 29 } 30 bool operator==(const S &rhs) const { return *i_ == *rhs.i_; } 31 int get() const { return *i_; } 32 int *i_; 33 }; 34 35 int main(int, char**) { 36 { 37 int a1[] = {1, 2, 3, 4}; 38 int a2[] = {1, 2, 4}; 39 std::list<int> c(a1, a1 + 4); 40 c.remove(3); 41 assert(c == std::list<int>(a2, a2 + 3)); 42 } 43 { // LWG issue #526 44 int a1[] = {1, 2, 1, 3, 5, 8, 11}; 45 int a2[] = {2, 3, 5, 8, 11}; 46 std::list<int> c(a1, a1 + 7); 47 c.remove(c.front()); 48 assert(c == std::list<int>(a2, a2 + 5)); 49 } 50 { 51 int a1[] = {1, 2, 1, 3, 5, 8, 11, 1}; 52 int a2[] = {2, 3, 5, 8, 11}; 53 std::list<S> c; 54 for (int *ip = a1; ip < a1 + 8; ++ip) 55 c.push_back(S(*ip)); 56 c.remove(c.front()); 57 std::list<S>::const_iterator it = c.begin(); 58 for (int *ip = a2; ip < a2 + 5; ++ip, ++it) { 59 assert(it != c.end()); 60 assert(*ip == it->get()); 61 } 62 assert(it == c.end()); 63 } 64 { 65 typedef no_default_allocator<int> Alloc; 66 typedef std::list<int, Alloc> List; 67 int a1[] = {1, 2, 3, 4}; 68 int a2[] = {1, 2, 4}; 69 List c(a1, a1 + 4, Alloc::create()); 70 c.remove(3); 71 assert(c == List(a2, a2 + 3, Alloc::create())); 72 } 73 #if TEST_STD_VER >= 11 74 { 75 int a1[] = {1, 2, 3, 4}; 76 int a2[] = {1, 2, 4}; 77 std::list<int, min_allocator<int>> c(a1, a1 + 4); 78 c.remove(3); 79 assert((c == std::list<int, min_allocator<int>>(a2, a2 + 3))); 80 } 81 #endif 82 83 return 0; 84 } 85