]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / sequences / deque / deque.cons / iter_iter_alloc.pass.cpp
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_iterators.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22
23 template <class InputIterator, class Allocator>
24 void
25 test(InputIterator f, InputIterator l, const Allocator& a)
26 {
27     typedef typename std::iterator_traits<InputIterator>::value_type T;
28     typedef std::deque<T, Allocator> C;
29     typedef typename C::const_iterator const_iterator;
30     C d(f, l, a);
31     assert(d.get_allocator() == a);
32     assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
33     assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
34     for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
35         assert(*i == *f);
36 }
37
38 int main()
39 {
40     int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
41     int* an = ab + sizeof(ab)/sizeof(ab[0]);
42     test(input_iterator<const int*>(ab), input_iterator<const int*>(an), test_allocator<int>(3));
43     test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), test_allocator<int>(4));
44     test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), test_allocator<int>(5));
45     test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), test_allocator<int>(6));
46 #if TEST_STD_VER >= 11
47     test(input_iterator<const int*>(ab), input_iterator<const int*>(an), min_allocator<int>());
48     test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), min_allocator<int>());
49     test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), min_allocator<int>());
50     test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), min_allocator<int>());
51 #endif
52 }