types.pass.cpp revision 6046aced820aaab4f14f2026531dd11d10690691
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <deque>
11
12// Test nested types and default template args:
13
14// template <class T, class Allocator = allocator<T> >
15// class deque
16// {
17// public:
18//     typedef T                                        value_type;
19//     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
36#include "../../test_allocator.h"
37#include "../../Copyable.h"
38
39template <class T, class Allocator>
40void
41test()
42{
43    typedef std::deque<T, Allocator> C;
44
45    static_assert((std::is_same<typename C::value_type, T>::value), "");
46    static_assert((std::is_same<typename C::value_type, typename 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 Allocator::size_type>::value), "");
49    static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), "");
50    static_assert((std::is_same<typename C::reference, typename Allocator::reference>::value), "");
51    static_assert((std::is_same<typename C::const_reference, typename Allocator::const_reference>::value), "");
52    static_assert((std::is_same<typename C::pointer, typename Allocator::pointer>::value), "");
53    static_assert((std::is_same<typename C::const_pointer, typename Allocator::const_pointer>::value), "");
54    static_assert((std::is_same<
55        typename std::iterator_traits<typename C::iterator>::iterator_category,
56        std::random_access_iterator_tag>::value), "");
57    static_assert((std::is_same<
58        typename std::iterator_traits<typename C::const_iterator>::iterator_category,
59        std::random_access_iterator_tag>::value), "");
60    static_assert((std::is_same<
61        typename C::reverse_iterator,
62        std::reverse_iterator<typename C::iterator> >::value), "");
63    static_assert((std::is_same<
64        typename C::const_reverse_iterator,
65        std::reverse_iterator<typename C::const_iterator> >::value), "");
66}
67
68int main()
69{
70    test<int, test_allocator<int> >();
71    test<int*, std::allocator<int*> >();
72    test<Copyable, test_allocator<Copyable> >();
73    static_assert((std::is_same<std::deque<char>::allocator_type,
74                                std::allocator<char> >::value), "");
75}
76