| 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 |
// vector(const vector& v, const allocator_type& a); |
| 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(const C& x, const typename C::allocator_type& a) |
| 22 |
{ |
| 23 |
typename C::size_type s = x.size(); |
| 24 |
C c(x, a); |
| 25 |
LIBCPP_ASSERT(c.__invariants()); |
| 26 |
assert(c.size() == s); |
| 27 |
assert(c == x); |
| 28 |
} |
| 29 |
|
| 30 |
TEST_CONSTEXPR_CXX20 bool tests() |
| 31 |
{ |
| 32 |
{ |
| 33 |
bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; |
| 34 |
bool* an = a + sizeof(a)/sizeof(a[0]); |
| 35 |
test(std::vector<bool>(a, an), std::allocator<bool>()); |
| 36 |
} |
| 37 |
{ |
| 38 |
std::vector<bool, test_allocator<bool> > l(3, true, test_allocator<bool>(5)); |
| 39 |
std::vector<bool, test_allocator<bool> > l2(l, test_allocator<bool>(3)); |
| 40 |
assert(l2 == l); |
| 41 |
assert(l2.get_allocator() == test_allocator<bool>(3)); |
| 42 |
} |
| 43 |
{ |
| 44 |
std::vector<bool, other_allocator<bool> > l(3, true, other_allocator<bool>(5)); |
| 45 |
std::vector<bool, other_allocator<bool> > l2(l, other_allocator<bool>(3)); |
| 46 |
assert(l2 == l); |
| 47 |
assert(l2.get_allocator() == other_allocator<bool>(3)); |
| 48 |
} |
| 49 |
#if TEST_STD_VER >= 11 |
| 50 |
{ |
| 51 |
bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; |
| 52 |
bool* an = a + sizeof(a)/sizeof(a[0]); |
| 53 |
test(std::vector<bool, min_allocator<bool>>(a, an), min_allocator<bool>()); |
| 54 |
} |
| 55 |
{ |
| 56 |
std::vector<bool, min_allocator<bool> > l(3, true, min_allocator<bool>()); |
| 57 |
std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>()); |
| 58 |
assert(l2 == l); |
| 59 |
assert(l2.get_allocator() == min_allocator<bool>()); |
| 60 |
} |
| 61 |
#endif |
| 62 |
|
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
int main(int, char**) |
| 67 |
{ |
| 68 |
tests(); |
| 69 |
#if TEST_STD_VER > 17 |
| 70 |
static_assert(tests()); |
| 71 |
#endif |
| 72 |
return 0; |
| 73 |
} |