blob: da9470d8a6c681043cb32ed5a0390b2c7cee267d [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <deque>
11
12// Test nested types and default template args:
13
Howard Hinnant6046ace2010-08-22 00:15:28 +000014// template <class T, class Allocator = allocator<T> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000015// class deque
Howard Hinnant6046ace2010-08-22 00:15:28 +000016// {
17// public:
18// typedef T value_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019// typedef Allocator allocator_type;
20// typedef typename allocator_type::reference reference;
21// typedef typename allocator_type::const_reference const_reference;
22// typedef implementation-defined iterator;
23// typedef implementation-defined const_iterator;
24// typedef typename allocator_type::size_type size_type;
25// typedef typename allocator_type::difference_type difference_type;
26// typedef typename allocator_type::pointer pointer;
27// typedef typename allocator_type::const_pointer const_pointer;
28// typedef std::reverse_iterator<iterator> reverse_iterator;
29// typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
30// };
31
32#include <deque>
33#include <iterator>
34#include <type_traits>
35
Marshall Clow1b921882013-12-03 00:18:10 +000036#include "test_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037#include "../../Copyable.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000038#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000039
40template <class T, class Allocator>
41void
42test()
43{
44 typedef std::deque<T, Allocator> C;
45
46 static_assert((std::is_same<typename C::value_type, T>::value), "");
47 static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), "");
48 static_assert((std::is_same<typename C::allocator_type, Allocator>::value), "");
49 static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), "");
50 static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), "");
51 static_assert((std::is_same<typename C::reference, typename Allocator::reference>::value), "");
52 static_assert((std::is_same<typename C::const_reference, typename Allocator::const_reference>::value), "");
53 static_assert((std::is_same<typename C::pointer, typename Allocator::pointer>::value), "");
54 static_assert((std::is_same<typename C::const_pointer, typename Allocator::const_pointer>::value), "");
55 static_assert((std::is_same<
56 typename std::iterator_traits<typename C::iterator>::iterator_category,
57 std::random_access_iterator_tag>::value), "");
58 static_assert((std::is_same<
59 typename std::iterator_traits<typename C::const_iterator>::iterator_category,
60 std::random_access_iterator_tag>::value), "");
61 static_assert((std::is_same<
62 typename C::reverse_iterator,
63 std::reverse_iterator<typename C::iterator> >::value), "");
64 static_assert((std::is_same<
65 typename C::const_reverse_iterator,
66 std::reverse_iterator<typename C::const_iterator> >::value), "");
67}
68
69int main()
70{
71 test<int, test_allocator<int> >();
72 test<int*, std::allocator<int*> >();
73 test<Copyable, test_allocator<Copyable> >();
74 static_assert((std::is_same<std::deque<char>::allocator_type,
75 std::allocator<char> >::value), "");
Howard Hinnantfcd8db72013-06-23 21:17:24 +000076#if __cplusplus >= 201103L
77 {
78 typedef std::deque<short, min_allocator<short>> C;
79 static_assert((std::is_same<C::value_type, short>::value), "");
80 static_assert((std::is_same<C::allocator_type, min_allocator<C::value_type> >::value), "");
81 static_assert((std::is_same<C::reference, C::value_type&>::value), "");
82 static_assert((std::is_same<C::const_reference, const C::value_type&>::value), "");
83 static_assert((std::is_same<C::pointer, min_pointer<C::value_type>>::value), "");
84 static_assert((std::is_same<C::const_pointer, min_pointer<const C::value_type>>::value), "");
Marshall Clow51349532014-07-08 15:19:40 +000085// min_allocator doesn't have a size_type, so one gets synthesized
86 static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), "");
Howard Hinnantfcd8db72013-06-23 21:17:24 +000087 static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
88 }
89#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090}