construct_iter_iter_alloc.pass.cpp revision bda804ea25ff0b96f66a80cbf4640a7b8dd886b8
1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===// 2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// 3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant// The LLVM Compiler Infrastructure 4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// 5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open 6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details. 7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// 8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===// 9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// <vector> 11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 12bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// template <class InputIter> vector(InputIter first, InputIter last, 13bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// const allocator_type& a); 14bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <vector> 16bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <cassert> 17bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 1883e2c4d877fe2d7793868b1c6a5d9525a7c4d431Marshall Clow#include "test_iterators.h" 19bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "../../../stack_allocator.h" 20061d0cc4db18d17bf01ed14c5db0be098205bd47Marshall Clow#include "min_allocator.h" 211f50f2d64baeb8130e1f47c379c12ee5d2400b72Marshall Clow#include "asan_testing.h" 22bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 23de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttemplate <class C, class Iterator, class A> 24bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantvoid 25de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttest(Iterator first, Iterator last, const A& a) 26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{ 27bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant C c(first, last, a); 28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(c.__invariants()); 29bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(c.size() == std::distance(first, last)); 301f50f2d64baeb8130e1f47c379c12ee5d2400b72Marshall Clow assert(is_contiguous_container_asan_correct(c)); 31bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) 32bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant assert(*i == *first); 33bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant} 34bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant 35de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant#if __cplusplus >= 201103L 36de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant 37de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttemplate <class T> 38de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnantstruct implicit_conv_allocator : min_allocator<T> 39de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant{ 40bda804ea25ff0b96f66a80cbf4640a7b8dd886b8Eric Fiselier implicit_conv_allocator(void*) {} 41de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant implicit_conv_allocator(const implicit_conv_allocator&) = default; 42de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant}; 43de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant 44de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant#endif 45de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant 46bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main() 47bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{ 482c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant { 49bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; 50bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant int* an = a + sizeof(a)/sizeof(a[0]); 51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant std::allocator<int> alloc; 52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); 53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); 54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); 55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); 56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant test<std::vector<int> >(a, an, alloc); 572c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant } 582c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant#if __cplusplus >= 201103L 592c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant { 602c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; 612c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant int* an = a + sizeof(a)/sizeof(a[0]); 622c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant min_allocator<int> alloc; 632c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); 642c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); 652c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); 662c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); 672c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant test<std::vector<int, min_allocator<int>> >(a, an, alloc); 68de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr); 692c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant } 702c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant#endif 71bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant} 72