1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <deque> |
10 | |
11 | // Test nested types and default template args: |
12 | |
13 | // template <class T, class Allocator = allocator<T> > |
14 | // class deque |
15 | // { |
16 | // public: |
17 | // typedef T value_type; |
18 | // typedef Allocator allocator_type; |
19 | // typedef typename allocator_type::reference reference; |
20 | // typedef typename allocator_type::const_reference const_reference; |
21 | // typedef implementation-defined iterator; |
22 | // typedef implementation-defined const_iterator; |
23 | // typedef typename allocator_type::size_type size_type; |
24 | // typedef typename allocator_type::difference_type difference_type; |
25 | // typedef typename allocator_type::pointer pointer; |
26 | // typedef typename allocator_type::const_pointer const_pointer; |
27 | // typedef std::reverse_iterator<iterator> reverse_iterator; |
28 | // typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
29 | // }; |
30 | |
31 | #include <deque> |
32 | #include <iterator> |
33 | #include <type_traits> |
34 | |
35 | #include "test_macros.h" |
36 | #include "test_allocator.h" |
37 | #include "../../Copyable.h" |
38 | #include "min_allocator.h" |
39 | |
40 | template <class T, class Allocator> |
41 | void |
42 | test() |
43 | { |
44 | typedef std::deque<T, Allocator> C; |
45 | |
46 | static_assert((std::is_same<typename C::value_type, T>::value), "" ); |
47 | static_assert( |
48 | (std::is_same<typename C::value_type, typename std::allocator_traits<Allocator>::value_type>::value), "" ); |
49 | static_assert((std::is_same<typename C::allocator_type, Allocator>::value), "" ); |
50 | static_assert( |
51 | (std::is_same<typename C::size_type, typename std::allocator_traits<Allocator>::size_type>::value), "" ); |
52 | static_assert( |
53 | (std::is_same<typename C::difference_type, typename std::allocator_traits<Allocator>::difference_type>::value), |
54 | "" ); |
55 | static_assert( |
56 | (std::is_same<typename C::reference, typename std::allocator_traits<Allocator>::value_type&>::value), "" ); |
57 | static_assert((std::is_same<typename C::const_reference, |
58 | const typename std::allocator_traits<Allocator>::value_type&>::value), |
59 | "" ); |
60 | static_assert((std::is_same<typename C::pointer, typename std::allocator_traits<Allocator>::pointer>::value), "" ); |
61 | static_assert( |
62 | (std::is_same<typename C::const_pointer, typename std::allocator_traits<Allocator>::const_pointer>::value), "" ); |
63 | static_assert((std::is_same< |
64 | typename std::iterator_traits<typename C::iterator>::iterator_category, |
65 | std::random_access_iterator_tag>::value), "" ); |
66 | static_assert((std::is_same< |
67 | typename std::iterator_traits<typename C::const_iterator>::iterator_category, |
68 | std::random_access_iterator_tag>::value), "" ); |
69 | static_assert((std::is_same< |
70 | typename C::reverse_iterator, |
71 | std::reverse_iterator<typename C::iterator> >::value), "" ); |
72 | static_assert((std::is_same< |
73 | typename C::const_reverse_iterator, |
74 | std::reverse_iterator<typename C::const_iterator> >::value), "" ); |
75 | static_assert((std::is_signed<typename C::difference_type>::value), "" ); |
76 | static_assert((std::is_unsigned<typename C::size_type>::value), "" ); |
77 | static_assert((std::is_same<typename C::difference_type, |
78 | typename std::iterator_traits<typename C::iterator>::difference_type>::value), "" ); |
79 | static_assert((std::is_same<typename C::difference_type, |
80 | typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "" ); |
81 | } |
82 | |
83 | int main(int, char**) |
84 | { |
85 | test<int, test_allocator<int> >(); |
86 | test<int*, std::allocator<int*> >(); |
87 | test<Copyable, test_allocator<Copyable> >(); |
88 | static_assert((std::is_same<std::deque<char>::allocator_type, |
89 | std::allocator<char> >::value), "" ); |
90 | |
91 | #if TEST_STD_VER >= 11 |
92 | { |
93 | typedef std::deque<short, min_allocator<short>> C; |
94 | static_assert((std::is_same<C::value_type, short>::value), "" ); |
95 | static_assert((std::is_same<C::allocator_type, min_allocator<C::value_type> >::value), "" ); |
96 | static_assert((std::is_same<C::reference, C::value_type&>::value), "" ); |
97 | static_assert((std::is_same<C::const_reference, const C::value_type&>::value), "" ); |
98 | static_assert((std::is_same<C::pointer, min_pointer<C::value_type>>::value), "" ); |
99 | static_assert((std::is_same<C::const_pointer, min_pointer<const C::value_type>>::value), "" ); |
100 | // min_allocator doesn't have a size_type, so one gets synthesized |
101 | static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), "" ); |
102 | static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "" ); |
103 | |
104 | static_assert((std::is_signed<typename C::difference_type>::value), "" ); |
105 | static_assert((std::is_unsigned<typename C::size_type>::value), "" ); |
106 | static_assert((std::is_same<typename C::difference_type, |
107 | typename std::iterator_traits<typename C::iterator>::difference_type>::value), "" ); |
108 | static_assert((std::is_same<typename C::difference_type, |
109 | typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "" ); |
110 | } |
111 | #endif |
112 | |
113 | return 0; |
114 | } |
115 | |