blob: 07824098fc6f7ca60921285b3d2d9dff59f1a69f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <vector>
11// vector<bool>
12
13// vector(const Alloc& = Alloc());
14
15#include <vector>
16#include <cassert>
17
Marshall Clow127db912015-06-04 00:10:20 +000018#include "test_macros.h"
Marshall Clow1b921882013-12-03 00:18:10 +000019#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000020#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
22template <class C>
23void
24test0()
25{
Marshall Clow127db912015-06-04 00:10:20 +000026#if TEST_STD_VER > 14
27 static_assert((noexcept(C{})), "" );
28#elif TEST_STD_VER >= 11
29 static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" );
30#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000031 C c;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070032 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033 assert(c.empty());
34 assert(c.get_allocator() == typename C::allocator_type());
Marshall Clow127db912015-06-04 00:10:20 +000035#if TEST_STD_VER >= 11
Marshall Clow48c74702014-03-05 19:06:20 +000036 C c1 = {};
Dan Albert1d4a1ed2016-05-25 22:36:09 -070037 assert(c1.__invariants());
Marshall Clow48c74702014-03-05 19:06:20 +000038 assert(c1.empty());
39 assert(c1.get_allocator() == typename C::allocator_type());
40#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041}
42
43template <class C>
44void
45test1(const typename C::allocator_type& a)
46{
Marshall Clow127db912015-06-04 00:10:20 +000047#if TEST_STD_VER > 14
48 static_assert((noexcept(C{typename C::allocator_type{}})), "" );
49#elif TEST_STD_VER >= 11
50 static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" );
51#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052 C c(a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070053 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000054 assert(c.empty());
55 assert(c.get_allocator() == a);
56}
57
58int main()
59{
60 {
61 test0<std::vector<bool> >();
62 test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3));
63 }
Marshall Clow127db912015-06-04 00:10:20 +000064#if TEST_STD_VER >= 11
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000065 {
66 test0<std::vector<bool, min_allocator<bool>> >();
67 test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>());
68 }
69#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070}