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 | // <array> |
10 | |
11 | // template <class T, size_t N > |
12 | // struct array |
13 | // { |
14 | // // types: |
15 | // typedef T& reference; |
16 | // typedef const T& const_reference; |
17 | // typedef implementation defined iterator; |
18 | // typedef implementation defined const_iterator; |
19 | // typedef T value_type; |
20 | // typedef T* pointer; |
21 | // typedef size_t size_type; |
22 | // typedef ptrdiff_t difference_type; |
23 | // typedef T value_type; |
24 | // typedef std::reverse_iterator<iterator> reverse_iterator; |
25 | // typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
26 | |
27 | #include <array> |
28 | #include <iterator> |
29 | #include <type_traits> |
30 | |
31 | #include "test_macros.h" |
32 | |
33 | template <class C> |
34 | void test_iterators() { |
35 | typedef std::iterator_traits<typename C::iterator> ItT; |
36 | typedef std::iterator_traits<typename C::const_iterator> CItT; |
37 | static_assert((std::is_same<typename ItT::iterator_category, std::random_access_iterator_tag>::value), "" ); |
38 | static_assert((std::is_same<typename ItT::value_type, typename C::value_type>::value), "" ); |
39 | static_assert((std::is_same<typename ItT::reference, typename C::reference>::value), "" ); |
40 | static_assert((std::is_same<typename ItT::pointer, typename C::pointer>::value), "" ); |
41 | static_assert((std::is_same<typename ItT::difference_type, typename C::difference_type>::value), "" ); |
42 | |
43 | static_assert((std::is_same<typename CItT::iterator_category, std::random_access_iterator_tag>::value), "" ); |
44 | static_assert((std::is_same<typename CItT::value_type, typename C::value_type>::value), "" ); |
45 | static_assert((std::is_same<typename CItT::reference, typename C::const_reference>::value), "" ); |
46 | static_assert((std::is_same<typename CItT::pointer, typename C::const_pointer>::value), "" ); |
47 | static_assert((std::is_same<typename CItT::difference_type, typename C::difference_type>::value), "" ); |
48 | } |
49 | |
50 | int main(int, char**) |
51 | { |
52 | { |
53 | typedef double T; |
54 | typedef std::array<T, 10> C; |
55 | static_assert((std::is_same<C::reference, T&>::value), "" ); |
56 | static_assert((std::is_same<C::const_reference, const T&>::value), "" ); |
57 | test_iterators<C>(); |
58 | static_assert((std::is_same<C::pointer, T*>::value), "" ); |
59 | static_assert((std::is_same<C::const_pointer, const T*>::value), "" ); |
60 | static_assert((std::is_same<C::size_type, std::size_t>::value), "" ); |
61 | static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "" ); |
62 | static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), "" ); |
63 | static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), "" ); |
64 | |
65 | static_assert((std::is_signed<typename C::difference_type>::value), "" ); |
66 | static_assert((std::is_unsigned<typename C::size_type>::value), "" ); |
67 | static_assert((std::is_same<typename C::difference_type, |
68 | typename std::iterator_traits<typename C::iterator>::difference_type>::value), "" ); |
69 | static_assert((std::is_same<typename C::difference_type, |
70 | typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "" ); |
71 | } |
72 | { |
73 | typedef int* T; |
74 | typedef std::array<T, 0> C; |
75 | static_assert((std::is_same<C::reference, T&>::value), "" ); |
76 | static_assert((std::is_same<C::const_reference, const T&>::value), "" ); |
77 | test_iterators<C>(); |
78 | static_assert((std::is_same<C::pointer, T*>::value), "" ); |
79 | static_assert((std::is_same<C::const_pointer, const T*>::value), "" ); |
80 | static_assert((std::is_same<C::size_type, std::size_t>::value), "" ); |
81 | static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "" ); |
82 | static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), "" ); |
83 | static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), "" ); |
84 | |
85 | static_assert((std::is_signed<typename C::difference_type>::value), "" ); |
86 | static_assert((std::is_unsigned<typename C::size_type>::value), "" ); |
87 | static_assert((std::is_same<typename C::difference_type, |
88 | typename std::iterator_traits<typename C::iterator>::difference_type>::value), "" ); |
89 | static_assert((std::is_same<typename C::difference_type, |
90 | typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "" ); |
91 | } |
92 | |
93 | return 0; |
94 | } |
95 | |