1f60c63c0SMarshall Clow //===----------------------------------------------------------------------===//
2f60c63c0SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f60c63c0SMarshall Clow //
7f60c63c0SMarshall Clow //===----------------------------------------------------------------------===//
802d11757SLouis Dionne
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14, c++17
10f60c63c0SMarshall Clow
11f60c63c0SMarshall Clow // <string>
12f60c63c0SMarshall Clow
13f60c63c0SMarshall Clow // template <class charT, class traits, class Allocator, class U>
143e895085SMarek Kurdej // typename basic_string<charT, traits, Allocator>::size_type
153e895085SMarek Kurdej // erase(basic_string<charT, traits, Allocator>& c, const U& value);
16f60c63c0SMarshall Clow
17f60c63c0SMarshall Clow #include <string>
18f60c63c0SMarshall Clow #include <optional>
19f60c63c0SMarshall Clow
20f60c63c0SMarshall Clow #include "test_macros.h"
21f60c63c0SMarshall Clow #include "test_allocator.h"
22f60c63c0SMarshall Clow #include "min_allocator.h"
23f60c63c0SMarshall Clow
24f60c63c0SMarshall Clow template <class S, class U>
test0(S s,U val,S expected,std::size_t expected_erased_count)25fb855eb9SMark de Wever void test0(S s, U val, S expected, std::size_t expected_erased_count) {
263e895085SMarek Kurdej ASSERT_SAME_TYPE(typename S::size_type, decltype(std::erase(s, val)));
273e895085SMarek Kurdej assert(expected_erased_count == std::erase(s, val));
28f60c63c0SMarshall Clow LIBCPP_ASSERT(s.__invariants());
29f60c63c0SMarshall Clow assert(s == expected);
30f60c63c0SMarshall Clow }
31f60c63c0SMarshall Clow
32f60c63c0SMarshall Clow template <class S>
test()33*a40bada9SBrendan Emery void test() {
343e895085SMarek Kurdej test0(S(""), 'a', S(""), 0);
35f60c63c0SMarshall Clow
363e895085SMarek Kurdej test0(S("a"), 'a', S(""), 1);
373e895085SMarek Kurdej test0(S("a"), 'b', S("a"), 0);
38f60c63c0SMarshall Clow
393e895085SMarek Kurdej test0(S("ab"), 'a', S("b"), 1);
403e895085SMarek Kurdej test0(S("ab"), 'b', S("a"), 1);
413e895085SMarek Kurdej test0(S("ab"), 'c', S("ab"), 0);
423e895085SMarek Kurdej test0(S("aa"), 'a', S(""), 2);
433e895085SMarek Kurdej test0(S("aa"), 'c', S("aa"), 0);
44f60c63c0SMarshall Clow
453e895085SMarek Kurdej test0(S("abc"), 'a', S("bc"), 1);
463e895085SMarek Kurdej test0(S("abc"), 'b', S("ac"), 1);
473e895085SMarek Kurdej test0(S("abc"), 'c', S("ab"), 1);
483e895085SMarek Kurdej test0(S("abc"), 'd', S("abc"), 0);
49f60c63c0SMarshall Clow
503e895085SMarek Kurdej test0(S("aab"), 'a', S("b"), 2);
513e895085SMarek Kurdej test0(S("aab"), 'b', S("aa"), 1);
523e895085SMarek Kurdej test0(S("aab"), 'c', S("aab"), 0);
533e895085SMarek Kurdej test0(S("abb"), 'a', S("bb"), 1);
543e895085SMarek Kurdej test0(S("abb"), 'b', S("a"), 2);
553e895085SMarek Kurdej test0(S("abb"), 'c', S("abb"), 0);
563e895085SMarek Kurdej test0(S("aaa"), 'a', S(""), 3);
573e895085SMarek Kurdej test0(S("aaa"), 'b', S("aaa"), 0);
58f60c63c0SMarshall Clow
59f60c63c0SMarshall Clow // Test cross-type erasure
60f60c63c0SMarshall Clow using opt = std::optional<typename S::value_type>;
613e895085SMarek Kurdej test0(S("aba"), opt(), S("aba"), 0);
623e895085SMarek Kurdej test0(S("aba"), opt('a'), S("b"), 2);
633e895085SMarek Kurdej test0(S("aba"), opt('b'), S("aa"), 1);
643e895085SMarek Kurdej test0(S("aba"), opt('c'), S("aba"), 0);
65f60c63c0SMarshall Clow }
66f60c63c0SMarshall Clow
main(int,char **)67*a40bada9SBrendan Emery int main(int, char**) {
68f60c63c0SMarshall Clow test<std::string>();
69f60c63c0SMarshall Clow test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
70f60c63c0SMarshall Clow test<std::basic_string<char, std::char_traits<char>, test_allocator<char>>>();
712df59c50SJF Bastien
722df59c50SJF Bastien return 0;
73f60c63c0SMarshall Clow }
74