blob: 1cc8e96e8cd489166f06ea66f4016e33605fe019 [file] [log] [blame]
Marshall Clowc5c29002015-05-26 18:57:27 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <array>
11
12// An string is a contiguous container
13
14#include <string>
15#include <cassert>
16
17#include "test_allocator.h"
18#include "min_allocator.h"
19
20
21template <class C>
22void test_contiguous ( const C &c )
23{
24 for ( size_t i = 0; i < c.size(); ++i )
Stephan T. Lavavej286adee2016-12-14 22:46:46 +000025 assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
Marshall Clowc5c29002015-05-26 18:57:27 +000026}
27
28int main()
29{
30 {
31 typedef std::string S;
32 test_contiguous(S());
33 test_contiguous(S("1"));
34 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));
35 }
36
37 {
38 typedef test_allocator<char> A;
39 typedef std::basic_string<char, std::char_traits<char>, A> S;
40 test_contiguous(S(A(3)));
41 test_contiguous(S("1", A(5)));
42 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
43 }
Eric Fiselierf2f2a632016-06-14 21:31:42 +000044#if TEST_STD_VER >= 11
Marshall Clowc5c29002015-05-26 18:57:27 +000045 {
46 typedef min_allocator<char> A;
47 typedef std::basic_string<char, std::char_traits<char>, A> S;
48 test_contiguous(S(A{}));
49 test_contiguous(S("1", A()));
50 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
51 }
52#endif
53}