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//===----------------------------------------------------------------------===//
8
9// <vector>
10
11// An vector is a contiguous container
12
13#include <vector>
14#include <cassert>
15
16#include "test_macros.h"
17#include "test_allocator.h"
18#include "min_allocator.h"
19
20template <class C>
21TEST_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));
24}
25
26TEST_CONSTEXPR_CXX20 bool tests() {
27 {
28 typedef int T;
29 typedef std::vector<T> C;
30 test_contiguous(C());
31 test_contiguous(C(3, 5));
32 }
33
34 {
35 typedef double T;
36 typedef test_allocator<T> A;
37 typedef std::vector<T, A> C;
38 test_contiguous(C(A(3)));
39 test_contiguous(C(7, 9.0, A(5)));
40 }
41#if TEST_STD_VER >= 11
42 {
43 typedef double T;
44 typedef min_allocator<T> A;
45 typedef std::vector<T, A> C;
46 test_contiguous(C(A{}));
47 test_contiguous(C(9, 11.0, A{}));
48 }
49 {
50 typedef double T;
51 typedef safe_allocator<T> A;
52 typedef std::vector<T, A> C;
53 test_contiguous(C(A{}));
54 test_contiguous(C(9, 11.0, A{}));
55 }
56#endif
57
58 return true;
59}
60
61int main(int, char**) {
62 tests();
63#if TEST_STD_VER > 17
64 static_assert(tests());
65#endif
66 return 0;
67}
68

source code of libcxx/test/std/containers/sequences/vector/contiguous.pass.cpp