blob: 7fa748a90d7123805157287bbc7ef74d35832e8e [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// const allocator_type& a);
14
15#include <vector>
16#include <cassert>
17
Marshall Clow83e2c4d2013-01-05 03:21:01 +000018#include "test_iterators.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019#include "../../../stack_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000020#include "min_allocator.h"
Marshall Clow1f50f2d2014-05-08 14:14:06 +000021#include "asan_testing.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022
Howard Hinnantde589f22013-09-21 21:13:54 +000023template <class C, class Iterator, class A>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000024void
Howard Hinnantde589f22013-09-21 21:13:54 +000025test(Iterator first, Iterator last, const A& a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000026{
27 C c(first, last, a);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070028 assert(c.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000029 assert(c.size() == std::distance(first, last));
Dan Albert1d4a1ed2016-05-25 22:36:09 -070030 assert(is_contiguous_container_asan_correct(c));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000031 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
32 assert(*i == *first);
33}
34
Dan Albert1d4a1ed2016-05-25 22:36:09 -070035#if __cplusplus >= 201103L
Howard Hinnantde589f22013-09-21 21:13:54 +000036
37template <class T>
38struct implicit_conv_allocator : min_allocator<T>
39{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070040 implicit_conv_allocator(void* p) {}
Howard Hinnantde589f22013-09-21 21:13:54 +000041 implicit_conv_allocator(const implicit_conv_allocator&) = default;
42};
43
44#endif
45
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000046int main()
47{
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000048 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
50 int* an = a + sizeof(a)/sizeof(a[0]);
51 std::allocator<int> alloc;
52 test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
53 test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
54 test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
55 test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
56 test<std::vector<int> >(a, an, alloc);
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000057 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070058#if __cplusplus >= 201103L
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000059 {
60 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
61 int* an = a + sizeof(a)/sizeof(a[0]);
62 min_allocator<int> alloc;
63 test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
64 test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
65 test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
66 test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
67 test<std::vector<int, min_allocator<int>> >(a, an, alloc);
Howard Hinnantde589f22013-09-21 21:13:54 +000068 test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr);
Howard Hinnant2c39cbe2013-06-27 19:35:32 +000069 }
70#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000071}