1c5c29006SMarshall Clow //===----------------------------------------------------------------------===//
2c5c29006SMarshall Clow //
3c5c29006SMarshall Clow //                     The LLVM Compiler Infrastructure
4c5c29006SMarshall Clow //
5c5c29006SMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open
6c5c29006SMarshall Clow // Source Licenses. See LICENSE.TXT for details.
7c5c29006SMarshall Clow //
8c5c29006SMarshall Clow //===----------------------------------------------------------------------===//
9c5c29006SMarshall Clow 
10c5c29006SMarshall Clow // <array>
11c5c29006SMarshall Clow 
12c5c29006SMarshall Clow // An string is a contiguous container
13c5c29006SMarshall Clow 
14c5c29006SMarshall Clow #include <string>
15c5c29006SMarshall Clow #include <cassert>
16c5c29006SMarshall Clow 
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 )
25*286adee5SStephan T. Lavavej         assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
26c5c29006SMarshall Clow }
27c5c29006SMarshall Clow 
28c5c29006SMarshall Clow int main()
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
53c5c29006SMarshall Clow }
54