Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // 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 Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <array> |
| 10 | |
| 11 | // An string is a contiguous container |
| 12 | |
| 13 | #include <string> |
| 14 | #include <cassert> |
| 15 | |
Marshall Clow | 7fc6a55 | 2019-05-31 18:35:30 +0000 | [diff] [blame^] | 16 | #include "test_macros.h" |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 17 | #include "test_allocator.h" |
| 18 | #include "min_allocator.h" |
| 19 | |
| 20 | |
| 21 | template <class C> |
| 22 | void test_contiguous ( const C &c ) |
| 23 | { |
| 24 | for ( size_t i = 0; i < c.size(); ++i ) |
Stephan T. Lavavej | 286adee | 2016-12-14 22:46:46 +0000 | [diff] [blame] | 25 | assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i)); |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 26 | } |
| 27 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 28 | int main(int, char**) |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 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 Fiselier | f2f2a63 | 2016-06-14 21:31:42 +0000 | [diff] [blame] | 44 | #if TEST_STD_VER >= 11 |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 45 | { |
| 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 |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 53 | |
| 54 | return 0; |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 55 | } |