]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/test/for_each_n_test.cpp
2 Copyright (c) Marshall Clow 2013.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 For more information, see http://www.boost.org
10 #include <boost/config.hpp>
11 #include <boost/algorithm/cxx17/for_each_n.hpp>
13 #include "iterator_test.hpp"
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp>
18 namespace ba
= boost::algorithm
;
24 void operator()(int& i
) {++i
; ++count
;}
27 int for_each_test::count
= 0;
29 void test_for_each_n ()
31 typedef input_iterator
<int*> Iter
;
32 int ia
[] = {0, 1, 2, 3, 4, 5};
33 const unsigned s
= sizeof(ia
)/sizeof(ia
[0]);
36 for_each_test::count
= 0;
37 Iter it
= ba::for_each_n(Iter(ia
), 0, for_each_test());
38 BOOST_CHECK(it
== Iter(ia
));
39 BOOST_CHECK(for_each_test::count
== 0);
43 for_each_test::count
= 0;
44 Iter it
= ba::for_each_n(Iter(ia
), s
, for_each_test());
46 BOOST_CHECK(it
== Iter(ia
+s
));
47 BOOST_CHECK(for_each_test::count
== s
);
48 for (unsigned i
= 0; i
< s
; ++i
)
49 BOOST_CHECK(ia
[i
] == static_cast<int>(i
+1));
53 for_each_test::count
= 0;
54 Iter it
= ba::for_each_n(Iter(ia
), 1, for_each_test());
56 BOOST_CHECK(it
== Iter(ia
+1));
57 BOOST_CHECK(for_each_test::count
== 1);
58 for (unsigned i
= 0; i
< 1; ++i
)
59 BOOST_CHECK(ia
[i
] == static_cast<int>(i
+2));
63 BOOST_AUTO_TEST_CASE( test_main
)