Marshall Clow | f60c63c | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Marshall Clow | f60c63c | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 |
| 9 | |
| 10 | // <string> |
| 11 | |
| 12 | // template <class charT, class traits, class Allocator, class Predicate> |
Louis Dionne | 6b77ebd | 2019-10-23 10:40:15 -0700 | [diff] [blame^] | 13 | // void erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); |
Marshall Clow | f60c63c | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 14 | |
| 15 | #include <string> |
| 16 | |
| 17 | #include "test_macros.h" |
| 18 | #include "test_allocator.h" |
| 19 | #include "min_allocator.h" |
| 20 | |
| 21 | template <class S, class Pred> |
| 22 | void |
| 23 | test0(S s, Pred p, S expected) |
| 24 | { |
| 25 | ASSERT_SAME_TYPE(void, decltype(std::erase_if(s, p))); |
| 26 | std::erase_if(s, p); |
| 27 | LIBCPP_ASSERT(s.__invariants()); |
| 28 | assert(s == expected); |
| 29 | } |
| 30 | |
| 31 | template <typename S> |
| 32 | void test() |
| 33 | { |
| 34 | auto isA = [](auto ch) { return ch == 'a';}; |
| 35 | auto isB = [](auto ch) { return ch == 'b';}; |
| 36 | auto isC = [](auto ch) { return ch == 'c';}; |
| 37 | auto isD = [](auto ch) { return ch == 'd';}; |
| 38 | auto True = [](auto) { return true; }; |
| 39 | auto False = [](auto) { return false; }; |
Louis Dionne | 6b77ebd | 2019-10-23 10:40:15 -0700 | [diff] [blame^] | 40 | |
Marshall Clow | f60c63c | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 41 | test0(S(""), isA, S("")); |
| 42 | |
| 43 | test0(S("a"), isA, S("")); |
| 44 | test0(S("a"), isB, S("a")); |
| 45 | |
| 46 | test0(S("ab"), isA, S("b")); |
| 47 | test0(S("ab"), isB, S("a")); |
| 48 | test0(S("ab"), isC, S("ab")); |
| 49 | test0(S("aa"), isA, S("")); |
| 50 | test0(S("aa"), isC, S("aa")); |
| 51 | |
| 52 | test0(S("abc"), isA, S("bc")); |
| 53 | test0(S("abc"), isB, S("ac")); |
| 54 | test0(S("abc"), isC, S("ab")); |
| 55 | test0(S("abc"), isD, S("abc")); |
| 56 | |
| 57 | test0(S("aab"), isA, S("b")); |
| 58 | test0(S("aab"), isB, S("aa")); |
| 59 | test0(S("aab"), isC, S("aab")); |
| 60 | test0(S("abb"), isA, S("bb")); |
| 61 | test0(S("abb"), isB, S("a")); |
| 62 | test0(S("abb"), isC, S("abb")); |
| 63 | test0(S("aaa"), isA, S("")); |
| 64 | test0(S("aaa"), isB, S("aaa")); |
| 65 | |
| 66 | test0(S("aba"), False, S("aba")); |
| 67 | test0(S("aba"), True, S("")); |
| 68 | } |
| 69 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 70 | int main(int, char**) |
Marshall Clow | f60c63c | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 71 | { |
| 72 | test<std::string>(); |
| 73 | test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>> (); |
| 74 | test<std::basic_string<char, std::char_traits<char>, test_allocator<char>>> (); |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 75 | |
| 76 | return 0; |
Marshall Clow | f60c63c | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 77 | } |