Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <vector> |
| 11 | |
| 12 | // template <class InputIter> vector(InputIter first, InputIter last); |
| 13 | |
| 14 | #include <vector> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 17 | #include "test_iterators.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | #include "../../../stack_allocator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 19 | #include "min_allocator.h" |
Marshall Clow | 1f50f2d | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 20 | #include "asan_testing.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
| 22 | template <class C, class Iterator> |
| 23 | void |
| 24 | test(Iterator first, Iterator last) |
| 25 | { |
| 26 | C c(first, last); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 27 | assert(c.__invariants()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | assert(c.size() == std::distance(first, last)); |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 29 | assert(is_contiguous_container_asan_correct(c)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) |
| 31 | assert(*i == *first); |
| 32 | } |
| 33 | |
| 34 | int 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 Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 49 | #if __cplusplus >= 201103L |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 50 | 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | } |