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<bool>
10
11// vector();
12// vector(const Alloc&);
13
14// This tests a conforming extension
15// For vector<>, this was added to the standard by N4258,
16// but vector<bool> was not changed.
17
18#include <vector>
19#include <cassert>
20
21#include "test_macros.h"
22#include "test_allocator.h"
23#include "min_allocator.h"
24
25template <class C>
26TEST_CONSTEXPR_CXX20 void test0() {
27#if TEST_STD_VER > 14
28 LIBCPP_STATIC_ASSERT((noexcept(C{})), "");
29#elif TEST_STD_VER >= 11
30 LIBCPP_STATIC_ASSERT((noexcept(C()) == noexcept(typename C::allocator_type())), "");
31#endif
32 C c;
33 LIBCPP_ASSERT(c.__invariants());
34 assert(c.empty());
35 assert(c.get_allocator() == typename C::allocator_type());
36#if TEST_STD_VER >= 11
37 C c1 = {};
38 LIBCPP_ASSERT(c1.__invariants());
39 assert(c1.empty());
40 assert(c1.get_allocator() == typename C::allocator_type());
41#endif
42}
43
44template <class C>
45TEST_CONSTEXPR_CXX20 void test1(const typename C::allocator_type& a) {
46#if TEST_STD_VER > 14
47 LIBCPP_STATIC_ASSERT((noexcept(C{typename C::allocator_type{}})), "");
48#elif TEST_STD_VER >= 11
49 LIBCPP_STATIC_ASSERT((noexcept(C(typename C::allocator_type())) ==
50 std::is_nothrow_copy_constructible<typename C::allocator_type>::value),
51 "");
52#endif
53 C c(a);
54 LIBCPP_ASSERT(c.__invariants());
55 assert(c.empty());
56 assert(c.get_allocator() == a);
57}
58
59TEST_CONSTEXPR_CXX20 bool tests() {
60 {
61 test0<std::vector<bool> >();
62 test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3));
63 }
64#if TEST_STD_VER >= 11
65 {
66 test0<std::vector<bool, min_allocator<bool>> >();
67 test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>());
68 }
69 {
70 test0<std::vector<bool, explicit_allocator<bool>> >();
71 test1<std::vector<bool, explicit_allocator<bool> > >(explicit_allocator<bool>());
72 }
73#endif
74
75 return true;
76}
77
78int main(int, char**) {
79 tests();
80#if TEST_STD_VER > 17
81 static_assert(tests());
82#endif
83 return 0;
84}
85

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