1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // basic_string(size_type n, charT c, const Allocator& a = Allocator()); // constexpr since C++20
19 #include "test_macros.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
23 template <class Alloc
, class charT
>
24 TEST_CONSTEXPR_CXX20
void test(unsigned n
, charT c
) {
25 typedef std::basic_string
<charT
, std::char_traits
<charT
>, Alloc
> S
;
27 LIBCPP_ASSERT(s2
.__invariants());
28 assert(s2
.size() == n
);
29 for (unsigned i
= 0; i
< n
; ++i
)
31 assert(s2
.get_allocator() == Alloc());
32 assert(s2
.capacity() >= s2
.size());
35 template <class Alloc
, class charT
>
36 TEST_CONSTEXPR_CXX20
void test(unsigned n
, charT c
, const Alloc
& a
) {
37 typedef std::basic_string
<charT
, std::char_traits
<charT
>, Alloc
> S
;
39 LIBCPP_ASSERT(s2
.__invariants());
40 assert(s2
.size() == n
);
41 for (unsigned i
= 0; i
< n
; ++i
)
43 assert(s2
.get_allocator() == a
);
44 assert(s2
.capacity() >= s2
.size());
47 template <class Alloc
, class Tp
>
48 TEST_CONSTEXPR_CXX20
void test(Tp n
, Tp c
) {
50 typedef std::basic_string
<charT
, std::char_traits
<charT
>, Alloc
> S
;
52 LIBCPP_ASSERT(s2
.__invariants());
53 assert(s2
.size() == static_cast<std::size_t>(n
));
54 for (int i
= 0; i
< n
; ++i
)
56 assert(s2
.get_allocator() == Alloc());
57 assert(s2
.capacity() >= s2
.size());
60 template <class Alloc
, class Tp
>
61 TEST_CONSTEXPR_CXX20
void test(Tp n
, Tp c
, const Alloc
& a
) {
63 typedef std::basic_string
<charT
, std::char_traits
<charT
>, Alloc
> S
;
65 LIBCPP_ASSERT(s2
.__invariants());
66 assert(s2
.size() == static_cast<std::size_t>(n
));
67 for (int i
= 0; i
< n
; ++i
)
69 assert(s2
.get_allocator() == a
);
70 assert(s2
.capacity() >= s2
.size());
73 template <class Alloc
>
74 TEST_CONSTEXPR_CXX20
void test_string(const Alloc
& a
) {
76 test
<Alloc
>(0, 'a', Alloc(a
));
79 test
<Alloc
>(1, 'a', Alloc(a
));
82 test
<Alloc
>(10, 'a', Alloc(a
));
84 test
<Alloc
>(100, 'a');
85 test
<Alloc
>(100, 'a', Alloc(a
));
87 test
<Alloc
>(static_cast<char>(100), static_cast<char>(65));
88 test
<Alloc
>(static_cast<char>(100), static_cast<char>(65), a
);
91 TEST_CONSTEXPR_CXX20
bool test() {
92 test_string(std::allocator
<char>());
93 test_string(test_allocator
<char>());
94 test_string(test_allocator
<char>(2));
95 #if TEST_STD_VER >= 11
96 test_string(min_allocator
<char>());
102 int main(int, char**) {
104 #if TEST_STD_VER > 17
105 static_assert(test());