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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <string>
10 
11 // basic_string<charT,traits,Allocator>&
12 //   assign(size_type n, charT c); // constexpr since C++20
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 #include "min_allocator.h"
19 
20 template <class S>
21 TEST_CONSTEXPR_CXX20 void
test(S s,typename S::size_type n,typename S::value_type c,S expected)22 test(S s, typename S::size_type n, typename S::value_type c, S expected)
23 {
24     s.assign(n, c);
25     LIBCPP_ASSERT(s.__invariants());
26     assert(s == expected);
27 }
28 
test()29 TEST_CONSTEXPR_CXX20 bool test() {
30   {
31     typedef std::string S;
32     test(S(), 0, 'a', S());
33     test(S(), 1, 'a', S(1, 'a'));
34     test(S(), 10, 'a', S(10, 'a'));
35     test(S(), 100, 'a', S(100, 'a'));
36 
37     test(S("12345"), 0, 'a', S());
38     test(S("12345"), 1, 'a', S(1, 'a'));
39     test(S("12345"), 10, 'a', S(10, 'a'));
40 
41     test(S("12345678901234567890"), 0, 'a', S());
42     test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
43     test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
44   }
45 #if TEST_STD_VER >= 11
46   {
47     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
48     test(S(), 0, 'a', S());
49     test(S(), 1, 'a', S(1, 'a'));
50     test(S(), 10, 'a', S(10, 'a'));
51     test(S(), 100, 'a', S(100, 'a'));
52 
53     test(S("12345"), 0, 'a', S());
54     test(S("12345"), 1, 'a', S(1, 'a'));
55     test(S("12345"), 10, 'a', S(10, 'a'));
56 
57     test(S("12345678901234567890"), 0, 'a', S());
58     test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
59     test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
60   }
61 #endif
62 
63   return true;
64 }
65 
main(int,char **)66 int main(int, char**)
67 {
68   test();
69 #if TEST_STD_VER > 17
70   static_assert(test());
71 #endif
72 
73   return 0;
74 }
75