Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.require / contiguous.pass.cpp
blob78908901686cf302bd0e06e3f25e911959b1a6a6
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <array>
11 // A string is a contiguous container
13 #include <string>
14 #include <cassert>
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
20 template <class C>
21 TEST_CONSTEXPR_CXX20 void test_contiguous(const C& c) {
22 for (std::size_t i = 0; i < c.size(); ++i)
23 assert(*(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
26 template <class Alloc>
27 TEST_CONSTEXPR_CXX20 void test_string(const Alloc& a) {
28 typedef std::basic_string<char, std::char_traits<char>, Alloc> S;
31 test_contiguous(S());
32 test_contiguous(S("1"));
33 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));
36 test_contiguous(S(Alloc()));
37 test_contiguous(S("1", Alloc()));
38 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc()));
41 test_contiguous(S(Alloc(a)));
42 test_contiguous(S("1", Alloc(a)));
43 test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc(a)));
47 TEST_CONSTEXPR_CXX20 bool test() {
48 test_string(std::allocator<char>());
49 test_string(test_allocator<char>());
50 test_string(test_allocator<char>(3));
51 #if TEST_STD_VER >= 11
52 test_string(min_allocator<char>());
53 #endif
55 return true;
58 int main(int, char**) {
59 test();
60 #if TEST_STD_VER > 17
61 static_assert(test());
62 #endif
64 return 0;