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"
21bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
22de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttemplate <class C, class Iterator, class A>
23bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantvoid
24de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttest(Iterator first, Iterator last, const A& a)
25bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    C c(first, last, a);
27bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(c.__invariants());
28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    assert(c.size() == std::distance(first, last));
29bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
30bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(*i == *first);
31bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
32bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
33de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant#if __cplusplus >= 201103L
34de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant
35de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttemplate <class T>
36de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnantstruct implicit_conv_allocator : min_allocator<T>
37de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant{
38de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant    implicit_conv_allocator(void* p) {}
39de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant    implicit_conv_allocator(const implicit_conv_allocator&) = default;
40de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant};
41de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant
42de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant#endif
43de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant
44bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main()
45bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
462c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    {
47bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
48bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int* an = a + sizeof(a)/sizeof(a[0]);
49bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    std::allocator<int> alloc;
50bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(a, an, alloc);
552c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    }
562c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant#if __cplusplus >= 201103L
572c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    {
582c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
592c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    int* an = a + sizeof(a)/sizeof(a[0]);
602c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    min_allocator<int> alloc;
612c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
622c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
632c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
642c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
652c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(a, an, alloc);
66de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant    test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr);
672c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    }
682c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant#endif
69bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
70