libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

erase_if.pass.cpp (1805B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
     10 
     11 // <set>
     12 
     13 // template <class T, class Compare, class Allocator, class Predicate>
     14 //   void 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 
     22 template <class S, class Pred>
     23 void
     24 test0(S s, Pred p, S expected)
     25 {
     26     ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p)));
     27     std::erase_if(s, p);
     28     assert(s == expected);
     29 }
     30 
     31 template <typename S>
     32 void test()
     33 {
     34     auto is1 = [](auto v) { return v == 1;};
     35     auto is2 = [](auto v) { return v == 2;};
     36     auto is3 = [](auto v) { return v == 3;};
     37     auto is4 = [](auto v) { return v == 4;};
     38     auto True  = [](auto) { return true; };
     39     auto False = [](auto) { return false; };
     40     
     41     test0(S(), is1, S());
     42 
     43     test0(S({1}), is1, S());
     44     test0(S({1}), is2, S({1}));
     45 
     46     test0(S({1,2}), is1, S({2}));
     47     test0(S({1,2}), is2, S({1}));
     48     test0(S({1,2}), is3, S({1,2}));
     49 
     50     test0(S({1,2,3}), is1, S({2,3}));
     51     test0(S({1,2,3}), is2, S({1,3}));
     52     test0(S({1,2,3}), is3, S({1,2}));
     53     test0(S({1,2,3}), is4, S({1,2,3}));
     54 
     55     test0(S({1,2,3}), True,  S());
     56     test0(S({1,2,3}), False, S({1,2,3}));
     57 }
     58 
     59 int main()
     60 {
     61     test<std::set<int>>();
     62     test<std::set<int, std::less<int>, min_allocator<int>>> ();
     63     test<std::set<int, std::less<int>, test_allocator<int>>> ();
     64 
     65     test<std::set<long>>();
     66     test<std::set<double>>();
     67 }