blob: fb2e3e6ce6bbb8e31e39a7d403ff7c10dd870f25 [file] [log] [blame]
Marshall Clowc5c29002015-05-26 18:57:27 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Marshall Clowc5c29002015-05-26 18:57:27 +00006//
7//===----------------------------------------------------------------------===//
8
9// <array>
10
11// An string is a contiguous container
12
13#include <string>
14#include <cassert>
15
16#include "test_allocator.h"
17#include "min_allocator.h"
18
19
20template <class C>
21void test_contiguous ( const C &c )
22{
23 for ( size_t i = 0; i < c.size(); ++i )
Stephan T. Lavavej286adee2016-12-14 22:46:46 +000024 assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
Marshall Clowc5c29002015-05-26 18:57:27 +000025}
26
27int main()
28{
29 {
30 typedef std::string S;
31 test_contiguous(S());
32 test_contiguous(S("1"));
33 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));
34 }
35
36 {
37 typedef test_allocator<char> A;
38 typedef std::basic_string<char, std::char_traits<char>, A> S;
39 test_contiguous(S(A(3)));
40 test_contiguous(S("1", A(5)));
41 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
42 }
Eric Fiselierf2f2a632016-06-14 21:31:42 +000043#if TEST_STD_VER >= 11
Marshall Clowc5c29002015-05-26 18:57:27 +000044 {
45 typedef min_allocator<char> A;
46 typedef std::basic_string<char, std::char_traits<char>, A> S;
47 test_contiguous(S(A{}));
48 test_contiguous(S("1", A()));
49 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
50 }
51#endif
52}