1c5c29006SMarshall Clow //===----------------------------------------------------------------------===//
2c5c29006SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6c5c29006SMarshall Clow //
7c5c29006SMarshall Clow //===----------------------------------------------------------------------===//
8c5c29006SMarshall Clow 
9c5c29006SMarshall Clow // <vector>
10c5c29006SMarshall Clow 
11c5c29006SMarshall Clow // An vector is a contiguous container
12c5c29006SMarshall Clow 
13c5c29006SMarshall Clow #include <vector>
14c5c29006SMarshall Clow #include <cassert>
15c5c29006SMarshall Clow 
167fc6a556SMarshall Clow #include "test_macros.h"
17c5c29006SMarshall Clow #include "test_allocator.h"
18c5c29006SMarshall Clow #include "min_allocator.h"
19c5c29006SMarshall Clow 
20c5c29006SMarshall Clow template <class C>
test_contiguous(const C & c)21*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 void test_contiguous(const C &c)
22c5c29006SMarshall Clow {
23c5c29006SMarshall Clow     for ( size_t i = 0; i < c.size(); ++i )
24286adee5SStephan T. Lavavej         assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
25c5c29006SMarshall Clow }
26c5c29006SMarshall Clow 
tests()27*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 bool tests()
28c5c29006SMarshall Clow {
29c5c29006SMarshall Clow     {
30c5c29006SMarshall Clow     typedef int T;
31c5c29006SMarshall Clow     typedef std::vector<T> C;
32c5c29006SMarshall Clow     test_contiguous(C());
33c5c29006SMarshall Clow     test_contiguous(C(3, 5));
34c5c29006SMarshall Clow     }
35c5c29006SMarshall Clow 
36c5c29006SMarshall Clow     {
37c5c29006SMarshall Clow     typedef double T;
38c5c29006SMarshall Clow     typedef test_allocator<T> A;
39c5c29006SMarshall Clow     typedef std::vector<T, A> C;
40c5c29006SMarshall Clow     test_contiguous(C(A(3)));
41c5c29006SMarshall Clow     test_contiguous(C(7, 9.0, A(5)));
42c5c29006SMarshall Clow     }
43f2f2a639SEric Fiselier #if TEST_STD_VER >= 11
44c5c29006SMarshall Clow     {
45c5c29006SMarshall Clow     typedef double T;
46cd6f7f9dSMarshall Clow     typedef min_allocator<T> A;
47c5c29006SMarshall Clow     typedef std::vector<T, A> C;
48cd6f7f9dSMarshall Clow     test_contiguous(C(A{}));
49cd6f7f9dSMarshall Clow     test_contiguous(C(9, 11.0, A{}));
50c5c29006SMarshall Clow     }
51c5c29006SMarshall Clow #endif
522df59c50SJF Bastien 
53*c74059c5SNikolas Klauser     return true;
54*c74059c5SNikolas Klauser }
55*c74059c5SNikolas Klauser 
main(int,char **)56*c74059c5SNikolas Klauser int main(int, char**)
57*c74059c5SNikolas Klauser {
58*c74059c5SNikolas Klauser     tests();
59*c74059c5SNikolas Klauser #if TEST_STD_VER > 17
60*c74059c5SNikolas Klauser     static_assert(tests());
61*c74059c5SNikolas Klauser #endif
622df59c50SJF Bastien     return 0;
63c5c29006SMarshall Clow }
64