]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iterator/test/distance_test.cpp
1 // Copyright (C) 2017 Michel Morin.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/container/slist.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/iterator/distance.hpp>
12 #include <boost/iterator/transform_iterator.hpp>
14 int twice(int x
) { return x
+ x
; }
16 template <typename Iterator
>
17 void test_distance(Iterator it_from
, Iterator it_to
, int n
)
19 BOOST_TEST(boost::distance(it_from
, it_to
) == n
);
24 int array
[3] = {1, 2, 3};
26 int* ptr2
= array
+ 3;
29 test_distance(ptr1
, ptr2
, 3);
30 test_distance(ptr2
, ptr1
, -3);
33 boost::make_transform_iterator(ptr1
, twice
)
34 , boost::make_transform_iterator(ptr2
, twice
)
38 boost::make_transform_iterator(ptr2
, twice
)
39 , boost::make_transform_iterator(ptr1
, twice
)
45 std::vector
<int> ints(ptr1
, ptr2
);
46 test_distance(ints
.begin(), ints
.end(), 3);
47 test_distance(ints
.end(), ints
.begin(), -3);
50 boost::make_transform_iterator(ints
.begin(), twice
)
51 , boost::make_transform_iterator(ints
.end(), twice
)
55 boost::make_transform_iterator(ints
.end(), twice
)
56 , boost::make_transform_iterator(ints
.begin(), twice
)
62 std::list
<int> ints(ptr1
, ptr2
);
63 test_distance(ints
.begin(), ints
.end(), 3);
66 boost::make_transform_iterator(ints
.begin(), twice
)
67 , boost::make_transform_iterator(ints
.end(), twice
)
73 boost::container::slist
<int> ints(ptr1
, ptr2
);
74 test_distance(ints
.begin(), ints
.end(), 3);
77 boost::make_transform_iterator(ints
.begin(), twice
)
78 , boost::make_transform_iterator(ints
.end(), twice
)
83 return boost::report_errors();