1 /* Boost.MultiIndex test for composite_key.
3 * Copyright 2003-2014 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_composite_key.hpp"
13 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
14 #include <boost/detail/lightweight_test.hpp>
15 #include "pre_multi_index.hpp"
16 #include <boost/multi_index_container.hpp>
17 #include <boost/multi_index/composite_key.hpp>
18 #include <boost/multi_index/hashed_index.hpp>
19 #include <boost/multi_index/member.hpp>
20 #include <boost/multi_index/ordered_index.hpp>
21 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
22 #include <boost/preprocessor/repetition/enum_params.hpp>
23 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
25 using namespace boost::multi_index;
26 using namespace boost::tuples;
28 struct is_composite_key_result_helper
31 struct no{char m[2];};
33 static no test(void*);
35 template<typename CompositeKey>
36 static yes test(composite_key_result<CompositeKey>*);
40 struct is_composite_key_result
42 typedef is_composite_key_result_helper helper;
44 BOOST_STATIC_CONSTANT(bool,
46 sizeof(helper::test((T*)0))==
47 sizeof(typename helper::yes)));
50 template<typename CompositeKeyResult>
51 struct composite_key_result_length
53 BOOST_STATIC_CONSTANT(int,
54 value=boost::tuples::length<
55 BOOST_DEDUCED_TYPENAME
56 CompositeKeyResult::composite_key_type::key_extractor_tuple
60 #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
61 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
62 struct is_boost_tuple_helper
65 struct no{char m[2];};
67 static no test(void*);
69 template<BOOST_PP_ENUM_PARAMS(10,typename T)>
70 static yes test(boost::tuple<BOOST_PP_ENUM_PARAMS(10,T)>*);
76 typedef is_boost_tuple_helper helper;
78 BOOST_STATIC_CONSTANT(bool,
80 sizeof(helper::test((T*)0))==
81 sizeof(typename helper::yes)));
85 struct composite_object_length
87 typedef typename boost::mpl::if_c<
88 is_composite_key_result<T>::value,
89 composite_key_result_length<T>,
90 typename boost::mpl::if_c<
91 is_boost_tuple<T>::value,
92 boost::tuples::length<T>,
97 BOOST_STATIC_CONSTANT(int,value=type::value);
101 struct composite_object_length
103 typedef typename boost::mpl::if_c<
104 is_composite_key_result<T>::value,
105 composite_key_result_length<T>,
106 boost::tuples::length<T>
109 BOOST_STATIC_CONSTANT(int,value=type::value);
113 template<typename CompositeKeyResult,typename T2>
114 struct comparison_equal_length
116 static bool is_less(const CompositeKeyResult& x,const T2& y)
118 composite_key_result_equal_to<CompositeKeyResult> eq;
119 composite_key_result_less<CompositeKeyResult> lt;
120 composite_key_result_greater<CompositeKeyResult> gt;
121 std::equal_to<CompositeKeyResult> std_eq;
122 std::less<CompositeKeyResult> std_lt;
123 std::greater<CompositeKeyResult> std_gt;
125 return (x< y) && !(y< x)&&
131 !eq(x,y) && !eq(y,x)&&
132 lt(x,y) && !lt(y,x)&&
133 !gt(x,y) && gt(y,x)&&
134 !std_eq(x,y) && !std_eq(y,x)&&
135 std_lt(x,y) && !std_lt(y,x)&&
136 !std_gt(x,y) && std_gt(y,x);
139 static bool is_greater(const CompositeKeyResult& x,const T2& y)
141 composite_key_result_equal_to<CompositeKeyResult> eq;
142 composite_key_result_less<CompositeKeyResult> lt;
143 composite_key_result_greater<CompositeKeyResult> gt;
144 std::equal_to<CompositeKeyResult> std_eq;
145 std::less<CompositeKeyResult> std_lt;
146 std::greater<CompositeKeyResult> std_gt;
148 return !(x< y) && (y< x)&&
154 !eq(x,y) && !eq(y,x)&&
155 !lt(x,y) && lt(y,x)&&
156 gt(x,y) && !gt(y,x)&&
157 !std_eq(x,y) && !std_eq(y,x)&&
158 !std_lt(x,y) && std_lt(y,x)&&
159 std_gt(x,y) && !std_gt(y,x);
162 static bool is_equiv(const CompositeKeyResult& x,const T2& y)
164 composite_key_result_equal_to<CompositeKeyResult> eq;
165 composite_key_result_less<CompositeKeyResult> lt;
166 composite_key_result_greater<CompositeKeyResult> gt;
167 std::equal_to<CompositeKeyResult> std_eq;
168 std::less<CompositeKeyResult> std_lt;
169 std::greater<CompositeKeyResult> std_gt;
171 return !(x< y) && !(y< x)&&
178 !lt(x,y) && !lt(y,x)&&
179 !gt(x,y) && !gt(y,x)&&
180 std_eq(x,y) && std_eq(y,x)&&
181 !std_lt(x,y) && !std_lt(y,x)&&
182 !std_gt(x,y) && !std_gt(y,x);
186 template<typename CompositeKeyResult,typename T2>
187 struct comparison_different_length
189 static bool is_less(const CompositeKeyResult& x,const T2& y)
191 composite_key_result_less<CompositeKeyResult> lt;
192 composite_key_result_greater<CompositeKeyResult> gt;
193 std::less<CompositeKeyResult> std_lt;
194 std::greater<CompositeKeyResult> std_gt;
196 return (x< y) && !(y< x)&&
200 lt(x,y) && !lt(y,x)&&
201 !gt(x,y) && gt(y,x)&&
202 std_lt(x,y) && !std_lt(y,x)&&
203 !std_gt(x,y) && std_gt(y,x);
206 static bool is_greater(const CompositeKeyResult& x,const T2& y)
208 composite_key_result_less<CompositeKeyResult> lt;
209 composite_key_result_greater<CompositeKeyResult> gt;
210 std::less<CompositeKeyResult> std_lt;
211 std::greater<CompositeKeyResult> std_gt;
213 return !(x< y) && (y< x)&&
217 !lt(x,y) && lt(y,x)&&
218 gt(x,y) && !gt(y,x)&&
219 !std_lt(x,y) && std_lt(y,x)&&
220 std_gt(x,y) && !std_gt(y,x);
223 static bool is_equiv(const CompositeKeyResult& x,const T2& y)
225 composite_key_result_less<CompositeKeyResult> lt;
226 composite_key_result_greater<CompositeKeyResult> gt;
227 std::less<CompositeKeyResult> std_lt;
228 std::greater<CompositeKeyResult> std_gt;
230 return !(x< y) && !(y< x)&&
234 !lt(x,y) && !lt(y,x)&&
235 !gt(x,y) && !gt(y,x)&&
236 !std_lt(x,y) && !std_lt(y,x)&&
237 !std_gt(x,y) && !std_gt(y,x);
241 template<typename CompositeKeyResult,typename T2>
242 struct comparison_helper:
244 composite_key_result_length<CompositeKeyResult>::value==
245 composite_object_length<T2>::value,
246 comparison_equal_length<CompositeKeyResult,T2>,
247 comparison_different_length<CompositeKeyResult,T2>
252 template<typename CompositeKeyResult,typename T2>
253 static bool is_less(const CompositeKeyResult& x,const T2& y)
255 return comparison_helper<CompositeKeyResult,T2>::is_less(x,y);
258 template<typename CompositeKeyResult,typename T2>
259 static bool is_greater(const CompositeKeyResult& x,const T2& y)
261 return comparison_helper<CompositeKeyResult,T2>::is_greater(x,y);
264 template<typename CompositeKeyResult,typename T2>
265 static bool is_equiv(const CompositeKeyResult& x,const T2& y)
267 return comparison_helper<CompositeKeyResult,T2>::is_equiv(x,y);
270 template<typename T1,typename T2,typename Compare>
271 static bool is_less(const T1& x,const T2& y,const Compare& c)
273 return c(x,y)&&!c(y,x);
276 template<typename T1,typename T2,typename Compare>
277 static bool is_greater(const T1& x,const T2& y,const Compare& c)
279 return c(y,x)&&!c(x,y);
282 template<typename T1,typename T2,typename Compare>
283 static bool is_equiv(const T1& x,const T2& y,const Compare& c)
285 return !c(x,y)&&!c(y,x);
288 template<typename T1,typename T2,typename Compare,typename Equiv>
290 const T1& x,const T2& y,const Compare& c,const Equiv& eq)
292 return c(x,y)&&!c(y,x)&&!eq(x,y)&&!eq(y,x);
295 template<typename T1,typename T2,typename Compare,typename Equiv>
296 static bool is_greater(
297 const T1& x,const T2& y,const Compare& c,const Equiv& eq)
299 return c(y,x)&&!c(x,y)&&!eq(x,y)&&!eq(y,x);
302 template<typename T1,typename T2,typename Compare,typename Equiv>
303 static bool is_equiv(
304 const T1& x,const T2& y,const Compare& c,const Equiv& eq)
306 return !c(x,y)&&!c(y,x)&&eq(x,y)&&eq(y,x);
311 xyz(int x_=0,int y_=0,int z_=0):x(x_),y(y_),z(z_){}
320 modulo_equal(int i):i_(i){}
321 bool operator ()(int x,int y)const{return (x%i_)==(y%i_);}
329 xystr(int x_=0,int y_=0,std::string str_=0):x(x_),y(y_),str(str_){}
336 #define TUPLE_MAKER_CREATE(z,n,tuple) \
337 template<BOOST_PP_ENUM_PARAMS(n,typename T)> \
338 static tuple<BOOST_PP_ENUM_PARAMS(n,T)> \
339 create(BOOST_PP_ENUM_BINARY_PARAMS(n,const T,& t)){ \
340 return tuple<BOOST_PP_ENUM_PARAMS(n,T)>( \
341 BOOST_PP_ENUM_PARAMS(n,t)); \
344 #define DEFINE_TUPLE_MAKER(name,tuple) \
347 static tuple<> create(){return tuple<>();} \
348 BOOST_PP_REPEAT_FROM_TO(1,5,TUPLE_MAKER_CREATE,tuple) \
351 DEFINE_TUPLE_MAKER(boost_tuple_maker,boost::tuple)
353 #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
354 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
355 DEFINE_TUPLE_MAKER(std_tuple_maker,std::tuple)
358 #undef DEFINE_TUPLE_MAKER
359 #undef TUPLE_MAKER_CREATE
361 template<typename TupleMaker>
362 void test_composite_key_template()
364 typedef composite_key<
366 BOOST_MULTI_INDEX_MEMBER(xyz,int,x),
367 BOOST_MULTI_INDEX_MEMBER(xyz,int,y),
368 BOOST_MULTI_INDEX_MEMBER(xyz,int,z)
371 typedef multi_index_container<
374 ordered_unique<ckey_t1>
379 mc1.insert(xyz(0,0,0));
380 mc1.insert(xyz(0,0,1));
381 mc1.insert(xyz(0,1,0));
382 mc1.insert(xyz(0,1,1));
383 mc1.insert(xyz(1,0,0));
384 mc1.insert(xyz(1,0,1));
385 mc1.insert(xyz(1,1,0));
386 mc1.insert(xyz(1,1,1));
388 BOOST_TEST(mc1.size()==8);
391 mc1.find(mc1.key_extractor()(xyz(0,0,0))),
392 mc1.find(mc1.key_extractor()(xyz(1,0,0))))==4);
395 mc1.find(TupleMaker::create(0,0,0)),
396 mc1.find(TupleMaker::create(1,0,0)))==4);
399 mc1.lower_bound(TupleMaker::create(0,0)),
400 mc1.upper_bound(TupleMaker::create(1,0)))==6);
402 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
406 mc1.upper_bound(1))==4);
413 BOOST_MULTI_INDEX_MEMBER(xyz,int,x)(),
414 BOOST_MULTI_INDEX_MEMBER(xyz,int,y)(),
415 BOOST_MULTI_INDEX_MEMBER(xyz,int,z)()));
416 ckey_t1 ck4(get<0>(ck1.key_extractors()));
418 ck3=ck3; /* prevent unused var */
420 get<2>(ck4.key_extractors())=
421 get<2>(ck2.key_extractors());
423 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),ck2(xyz(0,0,0))));
424 BOOST_TEST(is_less (ck1(xyz(0,0,1)),ck2(xyz(0,1,0))));
425 BOOST_TEST(is_greater(ck1(xyz(0,0,1)),ck2(xyz(0,0,0))));
427 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0)));
428 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(1)));
429 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(-1)));
430 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0)));
431 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,1)));
432 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,-1)));
433 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0,0)));
434 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,0,1)));
435 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,0,-1)));
436 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0,0,1)));
438 typedef composite_key_result_less<ckey_t1::result_type> ckey_comp_t1;
439 typedef composite_key_result_equal_to<ckey_t1::result_type> ckey_eq_t1;
444 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),ck2(xyz(0,0,0)),cp1,eq1));
445 BOOST_TEST(is_less (ck1(xyz(0,0,1)),ck2(xyz(0,1,0)),cp1,eq1));
446 BOOST_TEST(is_greater(ck1(xyz(0,0,1)),ck2(xyz(0,0,0)),cp1,eq1));
448 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0),cp1));
449 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(1),cp1));
450 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(-1),cp1));
452 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
453 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),0,cp1));
454 BOOST_TEST(is_less (ck1(xyz(0,0,0)),1,cp1));
455 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),-1,cp1));
458 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0),cp1));
459 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,1),cp1));
460 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,-1),cp1));
461 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0,0),cp1,eq1));
462 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,0,1),cp1,eq1));
463 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,0,-1),cp1,eq1));
465 typedef composite_key_result_greater<ckey_t1::result_type> ckey_comp_t2;
469 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),ck2(xyz(0,0,0)),cp2));
470 BOOST_TEST(is_greater(ck1(xyz(0,0,1)),ck2(xyz(0,1,0)),cp2));
471 BOOST_TEST(is_less (ck1(xyz(0,0,1)),ck2(xyz(0,0,0)),cp2));
473 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0),cp2));
474 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(1),cp2));
475 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(-1),cp2));
476 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0),cp2));
477 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,1),cp2));
478 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,-1),cp2));
479 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0,0),cp2));
480 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,0,1),cp2));
481 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,0,-1),cp2));
483 typedef composite_key_equal_to<
494 std::equal_to<int>(),
495 std::equal_to<int>()));
498 get<0>(eq3.key_eqs()),
499 get<1>(eq3.key_eqs()));
501 eq3=eq4; /* prevent unused var */
502 eq4=eq3; /* prevent unused var */
504 BOOST_TEST( eq2(ck1(xyz(0,0,0)),ck1(xyz(0,0,0))));
505 BOOST_TEST(!eq2(ck1(xyz(0,1,0)),ck1(xyz(0,0,0))));
506 BOOST_TEST(!eq2(ck1(xyz(0,2,0)),ck1(xyz(0,0,0))));
507 BOOST_TEST( eq2(ck1(xyz(0,3,0)),ck1(xyz(0,0,0))));
508 BOOST_TEST(!eq2(ck1(xyz(1,0,0)),ck1(xyz(0,0,0))));
509 BOOST_TEST(!eq2(ck1(xyz(1,1,0)),ck1(xyz(0,0,0))));
510 BOOST_TEST(!eq2(ck1(xyz(1,2,0)),ck1(xyz(0,0,0))));
511 BOOST_TEST(!eq2(ck1(xyz(1,3,0)),ck1(xyz(0,0,0))));
512 BOOST_TEST( eq2(ck1(xyz(2,0,0)),ck1(xyz(0,0,0))));
513 BOOST_TEST(!eq2(ck1(xyz(2,1,0)),ck1(xyz(0,0,0))));
514 BOOST_TEST(!eq2(ck1(xyz(2,2,0)),ck1(xyz(0,0,0))));
515 BOOST_TEST( eq2(ck1(xyz(2,3,0)),ck1(xyz(0,0,0))));
517 BOOST_TEST( eq2(TupleMaker::create(0,0,0),ck1(xyz(0,0,0))));
518 BOOST_TEST(!eq2(ck1(xyz(0,1,0)) ,TupleMaker::create(0,0,0)));
519 BOOST_TEST(!eq2(TupleMaker::create(0,2,0),ck1(xyz(0,0,0))));
520 BOOST_TEST( eq2(ck1(xyz(0,3,0)) ,TupleMaker::create(0,0,0)));
521 BOOST_TEST(!eq2(TupleMaker::create(1,0,0),ck1(xyz(0,0,0))));
522 BOOST_TEST(!eq2(ck1(xyz(1,1,0)) ,TupleMaker::create(0,0,0)));
523 BOOST_TEST(!eq2(TupleMaker::create(1,2,0),ck1(xyz(0,0,0))));
524 BOOST_TEST(!eq2(ck1(xyz(1,3,0)) ,TupleMaker::create(0,0,0)));
525 BOOST_TEST( eq2(TupleMaker::create(2,0,0),ck1(xyz(0,0,0))));
526 BOOST_TEST(!eq2(ck1(xyz(2,1,0)) ,TupleMaker::create(0,0,0)));
527 BOOST_TEST(!eq2(TupleMaker::create(2,2,0),ck1(xyz(0,0,0))));
528 BOOST_TEST( eq2(ck1(xyz(2,3,0)) ,TupleMaker::create(0,0,0)));
530 typedef composite_key_compare<
532 std::greater<int>, /* order reversed */
537 ckey_comp_t3 cp4(cp3);
543 ckey_comp_t3 cp6(get<0>(cp3.key_comps()));
545 cp4=cp5; /* prevent unused var */
546 cp5=cp6; /* prevent unused var */
547 cp6=cp4; /* prevent unused var */
549 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),ck2(xyz(0,0,0)),cp3));
550 BOOST_TEST(is_greater(ck1(xyz(0,0,1)),ck2(xyz(0,1,0)),cp3));
551 BOOST_TEST(is_greater(ck1(xyz(0,0,1)),ck2(xyz(0,0,0)),cp3));
553 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0),cp3));
554 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(1),cp3));
555 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(-1),cp3));
556 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0),cp3));
557 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,-1),cp3));
558 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,1),cp3));
559 BOOST_TEST(is_equiv (ck1(xyz(0,0,0)),TupleMaker::create(0,0,0),cp3));
560 BOOST_TEST(is_less (ck1(xyz(0,0,0)),TupleMaker::create(0,0,1),cp3));
561 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),TupleMaker::create(0,0,-1),cp3));
563 typedef composite_key<
565 BOOST_MULTI_INDEX_MEMBER(xyz,int,y), /* members reversed */
566 BOOST_MULTI_INDEX_MEMBER(xyz,int,x)
571 BOOST_TEST(is_equiv (ck1(xyz(0,0,1)),ck5(xyz(0,0,0))));
572 BOOST_TEST(is_less (ck1(xyz(0,0,0)),ck5(xyz(-1,1,0))));
573 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),ck5(xyz(1,-1,0))));
575 BOOST_TEST(is_equiv (ck1(xyz(0,0,1)),ck5(xyz(0,0,0)),cp1));
576 BOOST_TEST(is_less (ck1(xyz(0,0,0)),ck5(xyz(-1,1,0)),cp1));
577 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),ck5(xyz(1,-1,0)),cp1));
579 BOOST_TEST(is_equiv (ck1(xyz(0,0,1)),ck5(xyz(0,0,0)),cp2));
580 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),ck5(xyz(-1,1,0)),cp2));
581 BOOST_TEST(is_less (ck1(xyz(0,0,0)),ck5(xyz(1,-1,0)),cp2));
583 BOOST_TEST(is_equiv (ck1(xyz(0,0,1)),ck5(xyz(0,0,0)),cp3));
584 BOOST_TEST(is_less (ck1(xyz(0,0,0)),ck5(xyz(-1,1,0)),cp3));
585 BOOST_TEST(is_greater(ck1(xyz(0,0,0)),ck5(xyz(1,-1,0)),cp3));
587 typedef multi_index_container<
590 hashed_unique<ckey_t1>
595 mc2.insert(xyz(0,0,0));
596 mc2.insert(xyz(0,0,1));
597 mc2.insert(xyz(0,1,0));
598 mc2.insert(xyz(0,1,1));
599 mc2.insert(xyz(1,0,0));
600 mc2.insert(xyz(1,0,1));
601 mc2.insert(xyz(1,1,0));
602 mc2.insert(xyz(1,1,1));
603 mc2.insert(xyz(0,0,0));
604 mc2.insert(xyz(0,0,1));
605 mc2.insert(xyz(0,1,0));
606 mc2.insert(xyz(0,1,1));
607 mc2.insert(xyz(1,0,0));
608 mc2.insert(xyz(1,0,1));
609 mc2.insert(xyz(1,1,0));
610 mc2.insert(xyz(1,1,1));
612 BOOST_TEST(mc2.size()==8);
613 BOOST_TEST(mc2.find(TupleMaker::create(0,0,1))->z==1);
614 BOOST_TEST(ck1(*(mc2.find(TupleMaker::create(1,0,1))))==
615 TupleMaker::create(1,0,1));
617 typedef composite_key<
619 BOOST_MULTI_INDEX_MEMBER(xystr,std::string,str),
620 BOOST_MULTI_INDEX_MEMBER(xystr,int,x),
621 BOOST_MULTI_INDEX_MEMBER(xystr,int,y)
626 typedef composite_key_hash<
627 boost::hash<std::string>,
633 ckey_hash_t ch2(ch1);
636 boost::hash<std::string>(),
638 boost::hash<int>()));
639 ckey_hash_t ch4(get<0>(ch1.key_hash_functions()));
641 ch2=ch3; /* prevent unused var */
642 ch3=ch4; /* prevent unused var */
643 ch4=ch2; /* prevent unused var */
646 ch1(ck6(xystr(0,0,"hello")))==
647 ch1(TupleMaker::create(std::string("hello"),0,0)));
649 ch1(ck6(xystr(4,5,"world")))==
650 ch1(TupleMaker::create(std::string("world"),4,5)));
652 typedef boost::hash<composite_key_result<ckey_t3> > ckeyres_hash_t;
657 ch1(ck6(xystr(0,0,"hello")))==crh(ck6(xystr(0,0,"hello"))));
659 ch1(ck6(xystr(4,5,"world")))==crh(ck6(xystr(4,5,"world"))));
662 void test_composite_key()
664 test_composite_key_template<boost_tuple_maker>();
666 #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
667 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
668 test_composite_key_template<std_tuple_maker>();