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 // A string is a contiguous container
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
21 TEST_CONSTEXPR_CXX20
void test_contiguous(const C
& c
) {
22 for (std::size_t i
= 0; i
< c
.size(); ++i
)
23 assert(*(c
.begin() + static_cast<typename
C::difference_type
>(i
)) == *(std::addressof(*c
.begin()) + i
));
26 template <class Alloc
>
27 TEST_CONSTEXPR_CXX20
void test_string(const Alloc
& a
) {
28 typedef std::basic_string
<char, std::char_traits
<char>, Alloc
> S
;
32 test_contiguous(S("1"));
33 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));
36 test_contiguous(S(Alloc()));
37 test_contiguous(S("1", Alloc()));
38 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc()));
41 test_contiguous(S(Alloc(a
)));
42 test_contiguous(S("1", Alloc(a
)));
43 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc(a
)));
47 TEST_CONSTEXPR_CXX20
bool test() {
48 test_string(std::allocator
<char>());
49 test_string(test_allocator
<char>());
50 test_string(test_allocator
<char>(3));
51 #if TEST_STD_VER >= 11
52 test_string(min_allocator
<char>());
58 int main(int, char**) {
61 static_assert(test());