blob: e03389593f167ebdeb8dd46413aa8d73d403c014 [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
12// explicit vector(size_type n);
13
14#include <vector>
15#include <cassert>
16
Marshall Clowe27dbcf2013-12-02 17:00:56 +000017#include "DefaultOnly.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000018#include "min_allocator.h"
Marshall Clow1b921882013-12-03 00:18:10 +000019#include "test_allocator.h"
Marshall Clow1f50f2d2014-05-08 14:14:06 +000020#include "asan_testing.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
22template <class C>
23void
Marshall Clowa49a2c92013-09-14 00:47:59 +000024test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ())
25{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070026#if _LIBCPP_STD_VER > 11
Marshall Clowa49a2c92013-09-14 00:47:59 +000027 C c(n, a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070028 assert(c.__invariants());
Marshall Clowa49a2c92013-09-14 00:47:59 +000029 assert(c.size() == n);
30 assert(c.get_allocator() == a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070031 assert(is_contiguous_container_asan_correct(c));
32#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clowa49a2c92013-09-14 00:47:59 +000033 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
34 assert(*i == typename C::value_type());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070035#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clowa49a2c92013-09-14 00:47:59 +000036#endif
37}
38
39template <class C>
40void
41test1(typename C::size_type n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000042{
43 C c(n);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070044 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045 assert(c.size() == n);
46 assert(c.get_allocator() == typename C::allocator_type());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070047 assert(is_contiguous_container_asan_correct(c));
48#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
50 assert(*i == typename C::value_type());
Dan Albert1d4a1ed2016-05-25 22:36:09 -070051#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052}
53
Marshall Clowa49a2c92013-09-14 00:47:59 +000054template <class C>
55void
56test(typename C::size_type n)
57{
58 test1<C> ( n );
59 test2<C> ( n );
60}
61
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062int main()
63{
64 test<std::vector<int> >(50);
65 test<std::vector<DefaultOnly> >(500);
66 assert(DefaultOnly::count == 0);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070067#if __cplusplus >= 201103L
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000068 test<std::vector<int, min_allocator<int>> >(50);
69 test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500);
Marshall Clowa49a2c92013-09-14 00:47:59 +000070 test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23));
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000071 assert(DefaultOnly::count == 0);
72#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073}