1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <vector>
11 
12 // explicit vector(size_type n);
13 
14 #include <vector>
15 #include <cassert>
16 
17 #include "../../../DefaultOnly.h"
18 #include "../../../min_allocator.h"
19 #include "../../../test_allocator.h"
20 
21 template <class C>
22 void
23 test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ())
24 {
25 #if _LIBCPP_STD_VER > 11
26     C c(n, a);
27     assert(c.__invariants());
28     assert(c.size() == n);
29     assert(c.get_allocator() == a);
30 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
31     for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
32         assert(*i == typename C::value_type());
33 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
34 #endif
35 }
36 
37 template <class C>
38 void
39 test1(typename C::size_type n)
40 {
41     C c(n);
42     assert(c.__invariants());
43     assert(c.size() == n);
44     assert(c.get_allocator() == typename C::allocator_type());
45 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
46     for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
47         assert(*i == typename C::value_type());
48 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
49 }
50 
51 template <class C>
52 void
53 test(typename C::size_type n)
54 {
55     test1<C> ( n );
56     test2<C> ( n );
57 }
58 
59 int main()
60 {
61     test<std::vector<int> >(50);
62     test<std::vector<DefaultOnly> >(500);
63     assert(DefaultOnly::count == 0);
64 #if __cplusplus >= 201103L
65     test<std::vector<int, min_allocator<int>> >(50);
66     test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500);
67     test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23));
68     assert(DefaultOnly::count == 0);
69 #endif
70 }
71