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>
1798605940df7a54649618c541b972a308cccaade9Stephan T. Lavavej#include <cstddef>
18bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
19375e2f669cb882eb9a9700ab7fd1de8d2b57665fEric Fiselier#include "test_macros.h"
2083e2c4d877fe2d7793868b1c6a5d9525a7c4d431Marshall Clow#include "test_iterators.h"
21124ed406e56ed380279a6a05f996a96ff511af9dEric Fiselier#include "test_allocator.h"
22061d0cc4db18d17bf01ed14c5db0be098205bd47Marshall Clow#include "min_allocator.h"
231f50f2d64baeb8130e1f47c379c12ee5d2400b72Marshall Clow#include "asan_testing.h"
24bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
25de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttemplate <class C, class Iterator, class A>
26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantvoid
27de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttest(Iterator first, Iterator last, const A& a)
28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
29bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    C c(first, last, a);
30375e2f669cb882eb9a9700ab7fd1de8d2b57665fEric Fiselier    LIBCPP_ASSERT(c.__invariants());
3198605940df7a54649618c541b972a308cccaade9Stephan T. Lavavej    assert(c.size() == static_cast<std::size_t>(std::distance(first, last)));
32375e2f669cb882eb9a9700ab7fd1de8d2b57665fEric Fiselier    LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
33bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
34bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        assert(*i == *first);
35bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
36bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
37375e2f669cb882eb9a9700ab7fd1de8d2b57665fEric Fiselier#if TEST_STD_VER >= 11
38de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant
39de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnanttemplate <class T>
40de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnantstruct implicit_conv_allocator : min_allocator<T>
41de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant{
42bda804ea25ff0b96f66a80cbf4640a7b8dd886b8Eric Fiselier    implicit_conv_allocator(void*) {}
43de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant    implicit_conv_allocator(const implicit_conv_allocator&) = default;
443a974c6835a938df9fb86b7aebe01df2371298a2Eric Fiselier
453a974c6835a938df9fb86b7aebe01df2371298a2Eric Fiselier    template <class U>
463a974c6835a938df9fb86b7aebe01df2371298a2Eric Fiselier    implicit_conv_allocator(implicit_conv_allocator<U>) {}
47de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant};
48de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant
49de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant#endif
50de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant
51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main()
52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
532c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    {
54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int* an = a + sizeof(a)/sizeof(a[0]);
56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    std::allocator<int> alloc;
57bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
58bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
59bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
60bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    test<std::vector<int> >(a, an, alloc);
622c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    }
63375e2f669cb882eb9a9700ab7fd1de8d2b57665fEric Fiselier#if TEST_STD_VER >= 11
642c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    {
652c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
662c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    int* an = a + sizeof(a)/sizeof(a[0]);
672c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    min_allocator<int> alloc;
682c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc);
692c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc);
702c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc);
712c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc);
722c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    test<std::vector<int, min_allocator<int>> >(a, an, alloc);
73de589f2f8f9498f8006dc954e177a195ef6eb136Howard Hinnant    test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr);
742c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant    }
752c39cbe0207908bca2e1da40e16cbc443d2e7438Howard Hinnant#endif
76bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
77