66 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// UNSUPPORTED: c++03, c++11, c++14, c++179 10// <set>11 12// template <class T, class Compare, class Allocator, class Predicate>13// typename set<T, Compare, Allocator>::size_type14// erase_if(set<T, Compare, Allocator>& c, Predicate pred);15 16#include <set>17 18#include "test_macros.h"19#include "test_allocator.h"20#include "min_allocator.h"21 22template <class S, class Pred>23void test0(S s, Pred p, S expected, std::size_t expected_erased_count) {24 ASSERT_SAME_TYPE(typename S::size_type, decltype(std::erase_if(s, p)));25 assert(expected_erased_count == std::erase_if(s, p));26 assert(s == expected);27}28 29template <typename S>30void test() {31 auto is1 = [](auto v) { return v == 1; };32 auto is2 = [](auto v) { return v == 2; };33 auto is3 = [](auto v) { return v == 3; };34 auto is4 = [](auto v) { return v == 4; };35 auto True = [](auto) { return true; };36 auto False = [](auto) { return false; };37 38 test0(S(), is1, S(), 0);39 40 test0(S({1}), is1, S(), 1);41 test0(S({1}), is2, S({1}), 0);42 43 test0(S({1, 2}), is1, S({2}), 1);44 test0(S({1, 2}), is2, S({1}), 1);45 test0(S({1, 2}), is3, S({1, 2}), 0);46 47 test0(S({1, 2, 3}), is1, S({2, 3}), 1);48 test0(S({1, 2, 3}), is2, S({1, 3}), 1);49 test0(S({1, 2, 3}), is3, S({1, 2}), 1);50 test0(S({1, 2, 3}), is4, S({1, 2, 3}), 0);51 52 test0(S({1, 2, 3}), True, S(), 3);53 test0(S({1, 2, 3}), False, S({1, 2, 3}), 0);54}55 56int main(int, char**) {57 test<std::set<int>>();58 test<std::set<int, std::less<int>, min_allocator<int>>>();59 test<std::set<int, std::less<int>, test_allocator<int>>>();60 61 test<std::set<long>>();62 test<std::set<double>>();63 64 return 0;65}66