blob: 36e231acce126d89083667a0d3a182866ee64907 [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// template <class InputIter> vector(InputIter first, InputIter last);
13
14#include <vector>
15#include <cassert>
16
Marshall Clow83e2c4d2013-01-05 03:21:01 +000017#include "test_iterators.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000018#include "../../../stack_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000019#include "min_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, class Iterator>
23void
24test(Iterator first, Iterator last)
25{
26 C c(first, last);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070027 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000028 assert(c.size() == std::distance(first, last));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070029 assert(is_contiguous_container_asan_correct(c));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000030 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
31 assert(*i == *first);
32}
33
34int main()
35{
36 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
37 int* an = a + sizeof(a)/sizeof(a[0]);
38 test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
39 test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
40 test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
41 test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
42 test<std::vector<int> >(a, an);
43
44 test<std::vector<int, stack_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an));
45 test<std::vector<int, stack_allocator<int, 18> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
46 test<std::vector<int, stack_allocator<int, 18> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
47 test<std::vector<int, stack_allocator<int, 18> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
48 test<std::vector<int, stack_allocator<int, 18> > >(a, an);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070049#if __cplusplus >= 201103L
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000050 test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an));
51 test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an));
52 test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an));
53 test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an));
54 test<std::vector<int> >(a, an);
55#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056}