| 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 |
|
| 20 |
template <class C> |
| 21 |
TEST_CONSTEXPR_CXX20 void test_contiguous(const C &c) |
| 22 |
{ |
| 23 |
for ( std::size_t i = 0; i < c.size(); ++i ) |
| 24 |
assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i)); |
| 25 |
} |
| 26 |
|
| 27 |
TEST_CONSTEXPR_CXX20 bool tests() |
| 28 |
{ |
| 29 |
{ |
| 30 |
typedef int T; |
| 31 |
typedef std::vector<T> C; |
| 32 |
test_contiguous(C()); |
| 33 |
test_contiguous(C(3, 5)); |
| 34 |
} |
| 35 |
|
| 36 |
{ |
| 37 |
typedef double T; |
| 38 |
typedef test_allocator<T> A; |
| 39 |
typedef std::vector<T, A> C; |
| 40 |
test_contiguous(C(A(3))); |
| 41 |
test_contiguous(C(7, 9.0, A(5))); |
| 42 |
} |
| 43 |
#if TEST_STD_VER >= 11 |
| 44 |
{ |
| 45 |
typedef double T; |
| 46 |
typedef min_allocator<T> A; |
| 47 |
typedef std::vector<T, A> C; |
| 48 |
test_contiguous(C(A{})); |
| 49 |
test_contiguous(C(9, 11.0, A{})); |
| 50 |
} |
| 51 |
{ |
| 52 |
typedef double T; |
| 53 |
typedef safe_allocator<T> A; |
| 54 |
typedef std::vector<T, A> C; |
| 55 |
test_contiguous(C(A{})); |
| 56 |
test_contiguous(C(9, 11.0, A{})); |
| 57 |
} |
| 58 |
#endif |
| 59 |
|
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
int main(int, char**) |
| 64 |
{ |
| 65 |
tests(); |
| 66 |
#if TEST_STD_VER > 17 |
| 67 |
static_assert(tests()); |
| 68 |
#endif |
| 69 |
return 0; |
| 70 |
} |