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
40template <class T, class Allocator>
41void test() {
42 typedef std::deque<T, Allocator> C;
43
44 static_assert((std::is_same<typename C::value_type, T>::value), "");
45 static_assert(
46 (std::is_same<typename C::value_type, typename std::allocator_traits<Allocator>::value_type>::value), "");
47 static_assert((std::is_same<typename C::allocator_type, Allocator>::value), "");
48 static_assert((std::is_same<typename C::size_type, typename std::allocator_traits<Allocator>::size_type>::value), "");
49 static_assert(
50 (std::is_same<typename C::difference_type, typename std::allocator_traits<Allocator>::difference_type>::value),
51 "");
52 static_assert(
53 (std::is_same<typename C::reference, typename std::allocator_traits<Allocator>::value_type&>::value), "");
54 static_assert(
55 (std::is_same<typename C::const_reference, const typename std::allocator_traits<Allocator>::value_type&>::value),
56 "");
57 static_assert((std::is_same<typename C::pointer, typename std::allocator_traits<Allocator>::pointer>::value), "");
58 static_assert(
59 (std::is_same<typename C::const_pointer, typename std::allocator_traits<Allocator>::const_pointer>::value), "");
60 static_assert((std::is_same< typename std::iterator_traits<typename C::iterator>::iterator_category,
61 std::random_access_iterator_tag>::value),
62 "");
63 static_assert((std::is_same< typename std::iterator_traits<typename C::const_iterator>::iterator_category,
64 std::random_access_iterator_tag>::value),
65 "");
66 static_assert((std::is_same< typename C::reverse_iterator, std::reverse_iterator<typename C::iterator> >::value), "");
67 static_assert(
68 (std::is_same< typename C::const_reverse_iterator, std::reverse_iterator<typename C::const_iterator> >::value),
69 "");
70 static_assert((std::is_signed<typename C::difference_type>::value), "");
71 static_assert((std::is_unsigned<typename C::size_type>::value), "");
72 static_assert((std::is_same<typename C::difference_type,
73 typename std::iterator_traits<typename C::iterator>::difference_type>::value),
74 "");
75 static_assert((std::is_same<typename C::difference_type,
76 typename std::iterator_traits<typename C::const_iterator>::difference_type>::value),
77 "");
78}
79
80int main(int, char**) {
81 test<int, test_allocator<int> >();
82 test<int*, std::allocator<int*> >();
83 test<Copyable, test_allocator<Copyable> >();
84 static_assert((std::is_same<std::deque<char>::allocator_type, std::allocator<char> >::value), "");
85
86#if TEST_STD_VER >= 11
87 {
88 typedef std::deque<short, min_allocator<short>> C;
89 static_assert((std::is_same<C::value_type, short>::value), "");
90 static_assert((std::is_same<C::allocator_type, min_allocator<C::value_type> >::value), "");
91 static_assert((std::is_same<C::reference, C::value_type&>::value), "");
92 static_assert((std::is_same<C::const_reference, const C::value_type&>::value), "");
93 static_assert((std::is_same<C::pointer, min_pointer<C::value_type>>::value), "");
94 static_assert((std::is_same<C::const_pointer, min_pointer<const C::value_type>>::value), "");
95 // min_allocator doesn't have a size_type, so one gets synthesized
96 static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), "");
97 static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
98
99 static_assert((std::is_signed<typename C::difference_type>::value), "");
100 static_assert((std::is_unsigned<typename C::size_type>::value), "");
101 static_assert((std::is_same<typename C::difference_type,
102 typename std::iterator_traits<typename C::iterator>::difference_type>::value),
103 "");
104 static_assert((std::is_same<typename C::difference_type,
105 typename std::iterator_traits<typename C::const_iterator>::difference_type>::value),
106 "");
107 }
108#endif
109
110 return 0;
111}
112

source code of libcxx/test/std/containers/sequences/deque/types.pass.cpp