82 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME11 12// <deque>13 14// template <class T, class Allocator, class Predicate>15// typename deque<T, Allocator>::size_type16// erase_if(deque<T, Allocator>& c, Predicate pred);17 18#include "asan_testing.h"19#include <deque>20 21#include "test_macros.h"22#include "test_allocator.h"23#include "min_allocator.h"24 25template <class S, class Pred>26void test0(S s, Pred p, S expected, std::size_t expected_erased_count) {27 ASSERT_SAME_TYPE(typename S::size_type, decltype(std::erase_if(s, p)));28 assert(expected_erased_count == std::erase_if(s, p));29 assert(s == expected);30 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(s));31}32 33template <typename S>34void test() {35 auto is1 = [](auto v) { return v == 1; };36 auto is2 = [](auto v) { return v == 2; };37 auto is3 = [](auto v) { return v == 3; };38 auto is4 = [](auto v) { return v == 4; };39 auto True = [](auto) { return true; };40 auto False = [](auto) { return false; };41 42 test0(S(), is1, S(), 0);43 44 test0(S({1}), is1, S(), 1);45 test0(S({1}), is2, S({1}), 0);46 47 test0(S({1, 2}), is1, S({2}), 1);48 test0(S({1, 2}), is2, S({1}), 1);49 test0(S({1, 2}), is3, S({1, 2}), 0);50 test0(S({1, 1}), is1, S(), 2);51 test0(S({1, 1}), is3, S({1, 1}), 0);52 53 test0(S({1, 2, 3}), is1, S({2, 3}), 1);54 test0(S({1, 2, 3}), is2, S({1, 3}), 1);55 test0(S({1, 2, 3}), is3, S({1, 2}), 1);56 test0(S({1, 2, 3}), is4, S({1, 2, 3}), 0);57 58 test0(S({1, 1, 1}), is1, S(), 3);59 test0(S({1, 1, 1}), is2, S({1, 1, 1}), 0);60 test0(S({1, 1, 2}), is1, S({2}), 2);61 test0(S({1, 1, 2}), is2, S({1, 1}), 1);62 test0(S({1, 1, 2}), is3, S({1, 1, 2}), 0);63 test0(S({1, 2, 2}), is1, S({2, 2}), 1);64 test0(S({1, 2, 2}), is2, S({1}), 2);65 test0(S({1, 2, 2}), is3, S({1, 2, 2}), 0);66 67 test0(S({1, 2, 3}), True, S(), 3);68 test0(S({1, 2, 3}), False, S({1, 2, 3}), 0);69}70 71int main(int, char**) {72 test<std::deque<int>>();73 test<std::deque<int, min_allocator<int>>>();74 test<std::deque<int, safe_allocator<int>>>();75 test<std::deque<int, test_allocator<int>>>();76 77 test<std::deque<long>>();78 test<std::deque<double>>();79 80 return 0;81}82