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