]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/erasure.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / erasure.cc
CommitLineData
a62b871d 1// { dg-options "-std=gnu++2a" }
188588e4
ESR
2// { dg-do run { target c++2a } }
3
99dee823 4// Copyright (C) 2018-2021 Free Software Foundation, Inc.
188588e4
ESR
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
20
21#include <string>
22#include <testsuite_hooks.h>
23
0fe9eaaa
JW
24#ifndef __cpp_lib_erase_if
25# error "Feature-test macro for erase_if missing in <string>"
26#elif __cpp_lib_erase_if < 202002
27# error "Feature-test macro for erase_if has wrong value in <string>"
28#endif
29
188588e4
ESR
30void
31test01()
32{
33 auto is_vowel = [](const char c)
34 {
35 return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
36 };
37
38 std::string str("cute fluffy kittens");
0b44b4b8 39 auto num = std::erase_if(str, is_vowel);
188588e4 40 VERIFY( str == "ct flffy kttns" );
0b44b4b8 41 VERIFY( num == 5 );
188588e4
ESR
42}
43
44void
45test02()
46{
47 std::string str = "cute fluffy kittens";
0b44b4b8 48 auto num = std::erase(str, 'f');
188588e4 49 VERIFY( str == "cute luy kittens" );
0b44b4b8
ESR
50 VERIFY( num == 3 );
51 num = std::erase(str, 'z');
188588e4 52 VERIFY( str == "cute luy kittens" );
0b44b4b8 53 VERIFY( num == 0 );
188588e4
ESR
54}
55
56int
57main()
58{
59 test01();
60 test02();
61
62 return 0;
63}