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// <deque>
11
12// template <class InputIterator>
13//   deque(InputIterator f, InputIterator l, const allocator_type& a);
14
15#include <deque>
16#include <cassert>
17#include <cstddef>
18
19#include "test_macros.h"
20#include "test_iterators.h"
21#include "test_allocator.h"
22#include "min_allocator.h"
23#if TEST_STD_VER >= 11
24#include "emplace_constructible.h"
25#endif
26
27template <class InputIterator, class Allocator>
28void
29test(InputIterator f, InputIterator l, const Allocator& a)
30{
31    typedef typename std::iterator_traits<InputIterator>::value_type T;
32    typedef std::deque<T, Allocator> C;
33    typedef typename C::const_iterator const_iterator;
34    C d(f, l, a);
35    assert(d.get_allocator() == a);
36    assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
37    assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
38    for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
39        assert(*i == *f);
40}
41
42void basic_test()
43{
44    int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
45    int* an = ab + sizeof(ab)/sizeof(ab[0]);
46    test(input_iterator<const int*>(ab), input_iterator<const int*>(an), test_allocator<int>(3));
47    test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), test_allocator<int>(4));
48    test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), test_allocator<int>(5));
49    test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), test_allocator<int>(6));
50#if TEST_STD_VER >= 11
51    test(input_iterator<const int*>(ab), input_iterator<const int*>(an), min_allocator<int>());
52    test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), min_allocator<int>());
53    test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), min_allocator<int>());
54    test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), min_allocator<int>());
55#endif
56}
57
58
59void test_emplacable_concept() {
60#if TEST_STD_VER >= 11
61  int arr1[] = {42};
62  int arr2[] = {1, 101, 42};
63  {
64    using T = EmplaceConstructibleAndMoveable<int>;
65    using It = random_access_iterator<int*>;
66    std::allocator<T> a;
67    {
68      std::deque<T> v(It(arr1), It(std::end(arr1)), a);
69      assert(v[0].value == 42);
70    }
71    {
72      std::deque<T> v(It(arr2), It(std::end(arr2)), a);
73      assert(v[0].value == 1);
74      assert(v[1].value == 101);
75      assert(v[2].value == 42);
76    }
77  }
78  {
79    using T = EmplaceConstructibleAndMoveable<int>;
80    using It = input_iterator<int*>;
81    std::allocator<T> a;
82    {
83      std::deque<T> v(It(arr1), It(std::end(arr1)), a);
84      assert(v[0].copied == 0);
85      assert(v[0].value == 42);
86    }
87    {
88      std::deque<T> v(It(arr2), It(std::end(arr2)), a);
89      //assert(v[0].copied == 0);
90      assert(v[0].value == 1);
91      //assert(v[1].copied == 0);
92      assert(v[1].value == 101);
93      assert(v[2].copied == 0);
94      assert(v[2].value == 42);
95    }
96  }
97#endif
98}
99
100int main() {
101  basic_test();
102  test_emplacable_concept();
103}
104