]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/stl_interfaces/test/input.cpp
1 // Copyright (C) 2019 T. Zachary Laine
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/stl_interfaces/iterator_interface.hpp>
8 #include "ill_formed.hpp"
10 #include <boost/core/lightweight_test.hpp>
14 #include <type_traits>
17 struct basic_input_iter
18 : boost::stl_interfaces::
19 iterator_interface
<basic_input_iter
, std::input_iterator_tag
, int>
21 basic_input_iter() : it_(nullptr) {}
22 basic_input_iter(int * it
) : it_(it
) {}
24 int & operator*() const noexcept
{ return *it_
; }
25 basic_input_iter
& operator++() noexcept
30 friend bool operator==(basic_input_iter lhs
, basic_input_iter rhs
) noexcept
32 return lhs
.it_
== rhs
.it_
;
35 using base_type
= boost::stl_interfaces::
36 iterator_interface
<basic_input_iter
, std::input_iterator_tag
, int>;
37 using base_type::operator++;
43 BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(
44 basic_input_iter
, std::input_iterator
)
45 BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS(
47 std::input_iterator_tag
,
48 std::input_iterator_tag
,
54 template<typename ValueType
>
55 struct input_iter
: boost::stl_interfaces::iterator_interface
<
56 input_iter
<ValueType
>,
57 std::input_iterator_tag
,
60 input_iter() : it_(nullptr) {}
61 input_iter(ValueType
* it
) : it_(it
) {}
64 typename E
= std::enable_if_t
<
65 std::is_convertible
<ValueType2
*, ValueType
*>::value
>>
66 input_iter(input_iter
<ValueType2
> it
) : it_(it
.it_
)
69 ValueType
& operator*() const noexcept
{ return *it_
; }
70 input_iter
& operator++() noexcept
75 friend bool operator==(input_iter lhs
, input_iter rhs
) noexcept
77 return lhs
.it_
== rhs
.it_
;
80 using base_type
= boost::stl_interfaces::iterator_interface
<
81 input_iter
<ValueType
>,
82 std::input_iterator_tag
,
84 using base_type::operator++;
89 template<typename ValueType2
>
90 friend struct input_iter
;
93 BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(input_iter
<int>, std::input_iterator
)
94 BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS(
96 std::input_iterator_tag
,
97 std::input_iterator_tag
,
103 using int_input
= input_iter
<int>;
104 using const_int_input
= input_iter
<int const>;
105 using pair_input
= input_iter
<std::pair
<int, int>>;
106 using const_pair_input
= input_iter
<std::pair
<int, int> const>;
108 template<typename ValueType
>
109 struct proxy_input_iter
: boost::stl_interfaces::proxy_iterator_interface
<
110 proxy_input_iter
<ValueType
>,
111 std::input_iterator_tag
,
114 proxy_input_iter() : it_(nullptr) {}
115 proxy_input_iter(ValueType
* it
) : it_(it
) {}
118 typename E
= std::enable_if_t
<
119 std::is_convertible
<ValueType2
*, ValueType
*>::value
>>
120 proxy_input_iter(proxy_input_iter
<ValueType2
> it
) : it_(it
.it_
)
123 ValueType
operator*() const noexcept
{ return *it_
; }
124 proxy_input_iter
& operator++() noexcept
129 friend bool operator==(proxy_input_iter lhs
, proxy_input_iter rhs
) noexcept
131 return lhs
.it_
== rhs
.it_
;
134 using base_type
= boost::stl_interfaces::proxy_iterator_interface
<
135 proxy_input_iter
<ValueType
>,
136 std::input_iterator_tag
,
138 using base_type::operator++;
143 template<typename ValueType2
>
144 friend struct proxy_input_iter
;
147 using int_pair
= std::pair
<int, int>;
148 BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(
149 proxy_input_iter
<int_pair
>, std::input_iterator
)
150 BOOST_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS(
151 proxy_input_iter
<int_pair
>,
152 std::input_iterator_tag
,
153 std::input_iterator_tag
,
156 boost::stl_interfaces::proxy_arrow_result
<int_pair
>,
159 std::array
<int, 10> ints
= {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}};
160 std::array
<std::pair
<int, int>, 10> pairs
= {{
177 #include "view_tests.hpp"
180 using data_t
= decltype(std::declval
<T
>().data());
188 boost::stl_interfaces::v1::element_layout::discontiguous
>>::value
,
196 boost::stl_interfaces::v1::element_layout::discontiguous
> const>::
201 using size_t_
= decltype(std::declval
<T
>().size());
209 boost::stl_interfaces::v1::element_layout::discontiguous
>>::value
,
217 boost::stl_interfaces::v1::element_layout::discontiguous
> const>::
222 using back_t_
= decltype(std::declval
<T
>().back());
230 boost::stl_interfaces::v1::element_layout::discontiguous
>>::value
,
238 boost::stl_interfaces::v1::element_layout::discontiguous
> const>::
243 using index_operator_t
= decltype(std::declval
<T
>()[0]);
251 boost::stl_interfaces::v1::element_layout::discontiguous
>>::value
,
259 boost::stl_interfaces::v1::element_layout::discontiguous
> const>::
268 basic_input_iter
first(ints
.data());
269 basic_input_iter
last(ints
.data() + ints
.size());
272 std::array
<int, 10> ints_copy
;
273 std::copy(first
, last
, ints_copy
.begin());
274 BOOST_TEST(ints_copy
== ints
);
280 int_input
first(ints
.data());
281 int_input
last(ints
.data() + ints
.size());
282 const_int_input
first_copy(first
);
283 const_int_input
last_copy(last
);
284 std::equal(first
, last
, first_copy
, last_copy
);
289 int_input
first(ints
.data());
290 int_input
last(ints
.data() + ints
.size());
291 while (first
!= last
)
298 std::array
<int, 10> ints_copy
;
299 int_input
first(ints
.data());
300 int_input
last(ints
.data() + ints
.size());
301 std::copy(first
, last
, ints_copy
.begin());
302 BOOST_TEST(ints_copy
== ints
);
306 std::array
<std::pair
<int, int>, 10> pairs_copy
;
307 pair_input
first(pairs
.data());
308 pair_input
last(pairs
.data() + pairs
.size());
309 std::copy(first
, last
, pairs_copy
.begin());
310 BOOST_TEST(pairs_copy
== pairs
);
314 std::array
<int, 10> firsts_copy
;
315 pair_input
first(pairs
.data());
316 pair_input
last(pairs
.data() + pairs
.size());
317 for (auto out
= firsts_copy
.begin(); first
!= last
; ++first
) {
318 *out
++ = first
->first
;
320 BOOST_TEST(firsts_copy
== ints
);
324 std::array
<int, 10> firsts_copy
;
325 proxy_input_iter
<std::pair
<int, int>> first(pairs
.data());
326 proxy_input_iter
<std::pair
<int, int>> last(pairs
.data() + pairs
.size());
327 for (auto out
= firsts_copy
.begin(); first
!= last
; ++first
) {
328 *out
++ = first
->first
;
330 BOOST_TEST(firsts_copy
== ints
);
337 std::array
<int, 10> ints_copy
;
338 const_int_input
first(ints
.data());
339 const_int_input
last(ints
.data() + ints
.size());
340 std::copy(first
, last
, ints_copy
.begin());
341 BOOST_TEST(ints_copy
== ints
);
345 std::array
<std::pair
<int, int>, 10> pairs_copy
;
346 const_pair_input
first(pairs
.data());
347 const_pair_input
last(pairs
.data() + pairs
.size());
348 std::copy(first
, last
, pairs_copy
.begin());
349 BOOST_TEST(pairs_copy
== pairs
);
353 std::array
<int, 10> firsts_copy
;
354 const_pair_input
first(pairs
.data());
355 const_pair_input
last(pairs
.data() + pairs
.size());
356 for (auto out
= firsts_copy
.begin(); first
!= last
; ++first
) {
357 *out
++ = first
->first
;
359 BOOST_TEST(firsts_copy
== ints
);
363 std::array
<int, 10> firsts_copy
;
364 proxy_input_iter
<std::pair
<int, int> const> first(pairs
.data());
365 proxy_input_iter
<std::pair
<int, int> const> last(
366 pairs
.data() + pairs
.size());
367 for (auto out
= firsts_copy
.begin(); first
!= last
; ++first
) {
368 *out
++ = first
->first
;
370 BOOST_TEST(firsts_copy
== ints
);
375 basic_input_iter
first(ints
.data());
376 basic_input_iter
last(ints
.data() + ints
.size());
378 auto r
= range
<boost::stl_interfaces::v1::element_layout::discontiguous
>(
381 range
<boost::stl_interfaces::v1::element_layout::discontiguous
>(
386 std::array
<int, 10> ints_copy
;
387 std::copy(r
.begin(), r
.end(), ints_copy
.begin());
388 BOOST_TEST(ints_copy
== ints
);
390 BOOST_TEST(empty
.begin() == empty
.end());
395 BOOST_TEST(!r
.empty());
398 BOOST_TEST(empty
.empty());
402 BOOST_TEST(!cr
.empty());
405 auto const cempty
= empty
;
406 BOOST_TEST(cempty
.empty());
412 BOOST_TEST(r
.front() == 0);
415 BOOST_TEST(cr
.front() == 0);
419 return boost::report_errors();