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 // XFAIL: LIBCXX-AIX-FIXME
10 
11 // <array>
12 
13 // An string is a contiguous container
14 
15 #include <string>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "test_allocator.h"
20 #include "min_allocator.h"
21 
22 
23 template <class C>
24 TEST_CONSTEXPR_CXX20 void test_contiguous ( const C &c )
25 {
26     for ( size_t i = 0; i < c.size(); ++i )
27         assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
28 }
29 
30 TEST_CONSTEXPR_CXX20 bool test() {
31   {
32     typedef std::string S;
33     test_contiguous(S());
34     test_contiguous(S("1"));
35     test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));
36   }
37 
38   {
39     typedef test_allocator<char> A;
40     typedef std::basic_string<char, std::char_traits<char>, A> S;
41     test_contiguous(S(A(3)));
42     test_contiguous(S("1", A(5)));
43     test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
44   }
45 #if TEST_STD_VER >= 11
46   {
47     typedef min_allocator<char> A;
48     typedef std::basic_string<char, std::char_traits<char>, A> S;
49     test_contiguous(S(A{}));
50     test_contiguous(S("1", A()));
51     test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
52   }
53 #endif
54 
55   return true;
56 }
57 
58 int main(int, char**)
59 {
60   test();
61 #if TEST_STD_VER > 17
62   static_assert(test());
63 #endif
64 
65   return 0;
66 }
67