1 /* Boost.MultiIndex test for range().
3 * Copyright 2003-2015 Joaquin M Lopez Munoz.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org/libs/multi_index for library home page.
11 #include "test_range.hpp"
13 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
15 #include <boost/bind.hpp>
16 #include <boost/detail/lightweight_test.hpp>
17 #include "pre_multi_index.hpp"
18 #include <boost/multi_index_container.hpp>
19 #include <boost/multi_index/identity.hpp>
20 #include <boost/multi_index/ordered_index.hpp>
21 #include <boost/preprocessor/seq/enum.hpp>
24 using namespace boost::multi_index
;
26 typedef multi_index_container
<int> int_set
;
27 typedef int_set::iterator int_set_iterator
;
30 #define CHECK_RANGE(p,check_seq) \
32 int v[]={BOOST_PP_SEQ_ENUM(check_seq)};\
33 std::size_t size_v=sizeof(v)/sizeof(int);\
34 BOOST_TEST(std::size_t(std::distance((p).first,(p).second))==size_v);\
35 BOOST_TEST(std::equal((p).first,(p).second,&v[0]));\
38 #undef CHECK_VOID_RANGE
39 #define CHECK_VOID_RANGE(p) BOOST_TEST((p).first==(p).second)
42 #define BIND1ST(f,x) ::boost::bind(f,x,::boost::arg<1>())
45 #define BIND2ND(f,x) ::boost::bind(f,::boost::arg<1>(),x)
51 for(int i
=1;i
<=10;++i
)is
.insert(i
);
53 std::pair
<int_set::iterator
,int_set::iterator
> p
;
55 p
=is
.range(unbounded
,unbounded
);
56 CHECK_RANGE(p
,(1)(2)(3)(4)(5)(6)(7)(8)(9)(10));
59 BIND1ST(std::less
<int>(),5), /* 5 < x */
61 CHECK_RANGE(p
,(6)(7)(8)(9)(10));
64 BIND1ST(std::less_equal
<int>(),8), /* 8 <= x */
66 CHECK_RANGE(p
,(8)(9)(10));
69 BIND1ST(std::less_equal
<int>(),11), /* 11 <= x */
75 BIND2ND(std::less
<int>(),8)); /* x < 8 */
76 CHECK_RANGE(p
,(1)(2)(3)(4)(5)(6)(7));
80 BIND2ND(std::less_equal
<int>(),4)); /* x <= 4 */
81 CHECK_RANGE(p
,(1)(2)(3)(4));
85 BIND2ND(std::less_equal
<int>(),0)); /* x <= 0 */
89 BIND1ST(std::less
<int>(),6), /* 6 < x */
90 BIND2ND(std::less_equal
<int>(),9)); /* x <= 9 */
91 CHECK_RANGE(p
,(7)(8)(9));
94 BIND1ST(std::less_equal
<int>(),4), /* 4 <= x */
95 BIND2ND(std::less
<int>(),5)); /* x < 5 */
99 BIND1ST(std::less_equal
<int>(),10), /* 10 <= x */
100 BIND2ND(std::less_equal
<int>(),10)); /* x <= 10 */
104 BIND1ST(std::less
<int>(),0), /* 0 < x */
105 BIND2ND(std::less
<int>(),11)); /* x < 11 */
106 CHECK_RANGE(p
,(1)(2)(3)(4)(5)(6)(7)(8)(9)(10));
109 BIND1ST(std::less
<int>(),7), /* 7 < x */
110 BIND2ND(std::less_equal
<int>(),7)); /* x <= 7 */
112 BOOST_TEST(p
.first
==is
.upper_bound(7));
115 BIND1ST(std::less_equal
<int>(),8), /* 8 <= x */
116 BIND2ND(std::less
<int>(),2)); /* x < 2 */
118 BOOST_TEST(p
.first
==is
.lower_bound(8));
121 BIND1ST(std::less
<int>(),4), /* 4 < x */
122 BIND2ND(std::less
<int>(),5)); /* x < 5 */
124 BOOST_TEST(p
.first
!=is
.end());