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> deque(InputIterator f, InputIterator l);
13
14 #include <deque>
15 #include <cassert>
16
17 #include "../../../stack_allocator.h"
18 #include "test_iterators.h"
19 #include "min_allocator.h"
20
21 template <class InputIterator>
22 void
test(InputIterator f,InputIterator l)23 test(InputIterator f, InputIterator l)
24 {
25 typedef typename std::iterator_traits<InputIterator>::value_type T;
26 typedef std::allocator<T> Allocator;
27 typedef std::deque<T, Allocator> C;
28 typedef typename C::const_iterator const_iterator;
29 C d(f, l);
30 assert(d.size() == std::distance(f, l));
31 assert(distance(d.begin(), d.end()) == d.size());
32 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
33 assert(*i == *f);
34 }
35
36 template <class Allocator, class InputIterator>
37 void
test(InputIterator f,InputIterator l)38 test(InputIterator f, InputIterator l)
39 {
40 typedef typename std::iterator_traits<InputIterator>::value_type T;
41 typedef std::deque<T, Allocator> C;
42 typedef typename C::const_iterator const_iterator;
43 C d(f, l);
44 assert(d.size() == std::distance(f, l));
45 assert(distance(d.begin(), d.end()) == d.size());
46 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
47 assert(*i == *f);
48 }
49
main()50 int main()
51 {
52 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
53 int* an = ab + sizeof(ab)/sizeof(ab[0]);
54 test(input_iterator<const int*>(ab), input_iterator<const int*>(an));
55 test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an));
56 test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an));
57 test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an));
58 test<stack_allocator<int, 4096> >(ab, an);
59 #if __cplusplus >= 201103L
60 test<min_allocator<int> >(ab, an);
61 #endif
62 }
63