Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libc++ / trunk / test / containers / sequences / vector / vector.cons / construct_size.pass.cpp
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 #include "asan_testing.h"
21
22 template <class C>
23 void
24 test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ())
25 {
26 #if _LIBCPP_STD_VER > 11
27     C c(n, a);
28     assert(c.__invariants());
29     assert(c.size() == n);
30     assert(c.get_allocator() == a);
31     assert(is_contiguous_container_asan_correct(c)); 
32 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
33     for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
34         assert(*i == typename C::value_type());
35 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
36 #endif
37 }
38
39 template <class C>
40 void
41 test1(typename C::size_type n)
42 {
43     C c(n);
44     assert(c.__invariants());
45     assert(c.size() == n);
46     assert(c.get_allocator() == typename C::allocator_type());
47     assert(is_contiguous_container_asan_correct(c)); 
48 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
49     for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
50         assert(*i == typename C::value_type());
51 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
52 }
53
54 template <class C>
55 void
56 test(typename C::size_type n)
57 {
58     test1<C> ( n );
59     test2<C> ( n );
60 }
61
62 int main()
63 {
64     test<std::vector<int> >(50);
65     test<std::vector<DefaultOnly> >(500);
66     assert(DefaultOnly::count == 0);
67 #if __cplusplus >= 201103L
68     test<std::vector<int, min_allocator<int>> >(50);
69     test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500);
70     test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23));
71     assert(DefaultOnly::count == 0);
72 #endif
73 }