blob: 93ecbe87c380f765f103bcf4de22af9b21d6aead [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// explicit vector(size_type n);
14
15#include <vector>
16#include <cassert>
17
Marshall Clow061d0cc2013-11-26 20:58:02 +000018#include "min_allocator.h"
Marshall Clow1b921882013-12-03 00:18:10 +000019#include "test_allocator.h"
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000020
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021template <class C>
22void
Dan Albert1d4a1ed2016-05-25 22:36:09 -070023test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ())
Marshall Clowa49a2c92013-09-14 00:47:59 +000024{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070025#if _LIBCPP_STD_VER > 11
Marshall Clowa49a2c92013-09-14 00:47:59 +000026 C c(n, a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070027 assert(c.__invariants());
Marshall Clowa49a2c92013-09-14 00:47:59 +000028 assert(c.size() == n);
29 assert(c.get_allocator() == a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070030#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clowa49a2c92013-09-14 00:47:59 +000031 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
32 assert(*i == typename C::value_type());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070033#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clowa49a2c92013-09-14 00:47:59 +000034#endif
35}
36
37template <class C>
38void
39test1(typename C::size_type n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000040{
41 C c(n);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070042 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043 assert(c.size() == n);
44 assert(c.get_allocator() == typename C::allocator_type());
45 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
46 assert(*i == typename C::value_type());
47}
48
Marshall Clowa49a2c92013-09-14 00:47:59 +000049template <class C>
50void
51test(typename C::size_type n)
52{
53 test1<C> ( n );
54 test2<C> ( n );
55}
56
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000057int main()
58{
59 test<std::vector<bool> >(50);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070060#if __cplusplus >= 201103L
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000061 test<std::vector<bool, min_allocator<bool>> >(50);
Marshall Clowa49a2c92013-09-14 00:47:59 +000062 test2<std::vector<bool, test_allocator<bool>> >( 100, test_allocator<bool>(23));
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000063#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064}