]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | Copyright 2019 Glen Joseph Fernandes | |
3 | (glenjofe@gmail.com) | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. | |
6 | (http://www.boost.org/LICENSE_1_0.txt) | |
7 | */ | |
8 | #include <boost/config.hpp> | |
9 | #if !defined(BOOST_NO_CXX11_CONSTEXPR) && !defined(BOOST_NO_CXX11_DECLTYPE) | |
10 | #include <boost/core/span.hpp> | |
11 | #include <boost/core/lightweight_test_trait.hpp> | |
12 | ||
13 | template<class T> | |
14 | struct range { | |
15 | T* data() { | |
16 | return 0; | |
17 | } | |
18 | ||
19 | const T* data() const { | |
20 | return 0; | |
21 | } | |
22 | ||
23 | std::size_t size() const { | |
24 | return 0; | |
25 | } | |
26 | }; | |
27 | ||
28 | struct base { }; | |
29 | ||
30 | struct derived | |
31 | : base { }; | |
32 | ||
33 | void test_default() | |
34 | { | |
35 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible< | |
36 | boost::span<int> >)); | |
37 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible< | |
38 | boost::span<int, 0> >)); | |
39 | BOOST_TEST_TRAIT_FALSE((std::is_default_constructible< | |
40 | boost::span<int, 2> >)); | |
41 | } | |
42 | ||
43 | void test_data_size() | |
44 | { | |
45 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>, | |
46 | int*, std::size_t>)); | |
47 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>, | |
48 | int*, std::size_t>)); | |
49 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
50 | int, std::size_t>)); | |
51 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
52 | const int*, std::size_t>)); | |
53 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>, | |
54 | derived*, std::size_t>)); | |
55 | } | |
56 | ||
57 | void test_first_last() | |
58 | { | |
59 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>, | |
60 | int*, int*>)); | |
61 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>, | |
62 | int*, const int*>)); | |
63 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>, | |
64 | int*, int*>)); | |
65 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
66 | int, int*>)); | |
67 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
68 | const int*, int*>)); | |
69 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>, | |
70 | derived*, derived*>)); | |
71 | } | |
72 | ||
73 | void test_array() | |
74 | { | |
75 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>, | |
76 | int(&)[4]>)); | |
77 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int, 4>, | |
78 | int(&)[4]>)); | |
79 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 2>, | |
80 | int(&)[4]>)); | |
81 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>, | |
82 | int(&)[2]>)); | |
83 | } | |
84 | ||
85 | void test_std_array() | |
86 | { | |
87 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>, | |
88 | std::array<int, 4>&>)); | |
89 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>, | |
90 | std::array<int, 4>&>)); | |
91 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int, 4>, | |
92 | std::array<int, 4>&>)); | |
93 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int, | |
94 | 4>, std::array<int, 4>&>)); | |
95 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
96 | std::array<const int, 4>&>)); | |
97 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>, | |
98 | std::array<derived, 4>&>)); | |
99 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 2>, | |
100 | std::array<int, 4>&>)); | |
101 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>, | |
102 | std::array<const int, 4>&>)); | |
103 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base, 4>, | |
104 | std::array<derived, 4>&>)); | |
105 | } | |
106 | ||
107 | void test_const_std_array() | |
108 | { | |
109 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>, | |
110 | const std::array<int, 4> >)); | |
111 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int, | |
112 | 4>, const std::array<int, 4> >)); | |
113 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
114 | const std::array<int, 4> >)); | |
115 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<const | |
116 | base>, const std::array<derived, 4> >)); | |
117 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<const int, | |
118 | 2>, const std::array<int, 4> >)); | |
119 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>, | |
120 | const std::array<int, 4> >)); | |
121 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<const | |
122 | base, 4>, const std::array<derived, 4> >)); | |
123 | } | |
124 | ||
125 | void test_range() | |
126 | { | |
127 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>, | |
128 | range<int>&>)); | |
129 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>, | |
130 | range<int>&>)); | |
131 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>, | |
132 | range<int> >)); | |
133 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
134 | int*>)); | |
135 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
136 | range<int> >)); | |
137 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
138 | const range<int>&>)); | |
139 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>, | |
140 | range<derived>&>)); | |
141 | } | |
142 | ||
143 | void test_span() | |
144 | { | |
145 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int>, | |
146 | boost::span<int> >)); | |
147 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int>, | |
148 | boost::span<int, 4> >)); | |
149 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<int, 4>, | |
150 | boost::span<int> >)); | |
151 | BOOST_TEST_TRAIT_TRUE((std::is_constructible<boost::span<const int, | |
152 | 4>, boost::span<int, 4> >)); | |
153 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int>, | |
154 | boost::span<const int> >)); | |
155 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base>, | |
156 | boost::span<derived> >)); | |
157 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 2>, | |
158 | boost::span<int, 4> >)); | |
159 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<int, 4>, | |
160 | boost::span<const int, 4> >)); | |
161 | BOOST_TEST_TRAIT_FALSE((std::is_constructible<boost::span<base, 4>, | |
162 | boost::span<derived, 4> >)); | |
163 | } | |
164 | ||
165 | void test_copy() | |
166 | { | |
167 | BOOST_TEST_TRAIT_TRUE((std::is_copy_constructible< | |
168 | boost::span<int> >)); | |
169 | BOOST_TEST_TRAIT_TRUE((std::is_copy_constructible< | |
170 | boost::span<int, 4> >)); | |
171 | } | |
172 | ||
173 | void test_assign() | |
174 | { | |
175 | BOOST_TEST_TRAIT_TRUE((std::is_copy_assignable< | |
176 | boost::span<int> >)); | |
177 | BOOST_TEST_TRAIT_TRUE((std::is_copy_assignable< | |
178 | boost::span<int, 4> >)); | |
179 | } | |
180 | ||
181 | int main() | |
182 | { | |
183 | test_default(); | |
184 | test_data_size(); | |
185 | test_first_last(); | |
186 | test_array(); | |
187 | test_std_array(); | |
188 | test_const_std_array(); | |
189 | test_range(); | |
190 | test_span(); | |
191 | test_copy(); | |
192 | test_assign(); | |
193 | return boost::report_errors(); | |
194 | } | |
195 | #else | |
196 | int main() | |
197 | { | |
198 | return 0; | |
199 | } | |
200 | #endif |