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 
16*7fc6a556SMarshall 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>
22c5c29006SMarshall Clow 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 
282df59c50SJF Bastien int main(int, char**)
29c5c29006SMarshall Clow {
30c5c29006SMarshall Clow     {
31c5c29006SMarshall Clow     typedef std::string S;
32c5c29006SMarshall Clow     test_contiguous(S());
33c5c29006SMarshall Clow     test_contiguous(S("1"));
34c5c29006SMarshall Clow     test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));
35c5c29006SMarshall Clow     }
36c5c29006SMarshall Clow 
37c5c29006SMarshall Clow     {
38c5c29006SMarshall Clow     typedef test_allocator<char> A;
39c5c29006SMarshall Clow     typedef std::basic_string<char, std::char_traits<char>, A> S;
40c5c29006SMarshall Clow     test_contiguous(S(A(3)));
41c5c29006SMarshall Clow     test_contiguous(S("1", A(5)));
42c5c29006SMarshall Clow     test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
43c5c29006SMarshall Clow     }
44f2f2a639SEric Fiselier #if TEST_STD_VER >= 11
45c5c29006SMarshall Clow     {
46c5c29006SMarshall Clow     typedef min_allocator<char> A;
47c5c29006SMarshall Clow     typedef std::basic_string<char, std::char_traits<char>, A> S;
48c5c29006SMarshall Clow     test_contiguous(S(A{}));
49c5c29006SMarshall Clow     test_contiguous(S("1", A()));
50c5c29006SMarshall Clow     test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
51c5c29006SMarshall Clow     }
52c5c29006SMarshall Clow #endif
532df59c50SJF Bastien 
542df59c50SJF Bastien   return 0;
55c5c29006SMarshall Clow }
56