construct_iter_iter_alloc.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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// template <class InputIter> vector(InputIter first, InputIter last, 13// const allocator_type& a); 14 15#include <vector> 16#include <cassert> 17 18#include "../../../iterators.h" 19#include "../../../stack_allocator.h" 20 21template <class C, class Iterator> 22void 23test(Iterator first, Iterator last, const typename C::allocator_type& a) 24{ 25 C c(first, last, a); 26 assert(c.__invariants()); 27 assert(c.size() == std::distance(first, last)); 28 for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) 29 assert(*i == *first); 30} 31 32int main() 33{ 34 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; 35 int* an = a + sizeof(a)/sizeof(a[0]); 36 std::allocator<int> alloc; 37 test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); 38 test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); 39 test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); 40 test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); 41 test<std::vector<int> >(a, an, alloc); 42} 43