| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514 |
- /* Copyright 2003-2015 Joaquin M Lopez Munoz.
- * Distributed under the Boost Software License, Version 1.0.
- * (See accompanying file LICENSE_1_0.txt or copy at
- * http://www.boost.org/LICENSE_1_0.txt)
- *
- * See http://www.boost.org/libs/multi_index for library home page.
- */
- #ifndef BOOST_MULTI_INDEX_COMPOSITE_KEY_HPP
- #define BOOST_MULTI_INDEX_COMPOSITE_KEY_HPP
- #if defined(_MSC_VER)
- #pragma once
- #endif
- #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
- #include <boost/functional/hash_fwd.hpp>
- #include <boost/multi_index/detail/access_specifier.hpp>
- #include <boost/mpl/eval_if.hpp>
- #include <boost/mpl/identity.hpp>
- #include <boost/mpl/if.hpp>
- #include <boost/mpl/or.hpp>
- #include <boost/preprocessor/cat.hpp>
- #include <boost/preprocessor/control/expr_if.hpp>
- #include <boost/preprocessor/list/at.hpp>
- #include <boost/preprocessor/repetition/enum.hpp>
- #include <boost/preprocessor/repetition/enum_params.hpp>
- #include <boost/static_assert.hpp>
- #include <boost/tuple/tuple.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <boost/utility/enable_if.hpp>
- #include <functional>
- #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
- #include <boost/ref.hpp>
- #endif
- #if !defined(BOOST_NO_SFINAE)
- #include <boost/type_traits/is_convertible.hpp>
- #endif
- #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
- !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- #include <boost/multi_index/detail/cons_stdtuple.hpp>
- #endif
- /* A composite key stores n key extractors and "computes" the
- * result on a given value as a packed reference to the value and
- * the composite key itself. Actual invocations to the component
- * key extractors are lazily performed when executing an operation
- * on composite_key results (equality, comparison, hashing.)
- * As the other key extractors in Boost.MultiIndex, composite_key<T,...>
- * is overloaded to work on chained pointers to T and reference_wrappers
- * of T.
- */
- /* This user_definable macro limits the number of elements of a composite
- * key; useful for shortening resulting symbol names (MSVC++ 6.0, for
- * instance has problems coping with very long symbol names.)
- * NB: This cannot exceed the maximum number of arguments of
- * boost::tuple. In Boost 1.32, the limit is 10.
- */
- #if !defined(BOOST_MULTI_INDEX_LIMIT_COMPOSITE_KEY_SIZE)
- #define BOOST_MULTI_INDEX_LIMIT_COMPOSITE_KEY_SIZE 10
- #endif
- /* maximum number of key extractors in a composite key */
- #if BOOST_MULTI_INDEX_LIMIT_COMPOSITE_KEY_SIZE<10 /* max length of a tuple */
- #define BOOST_MULTI_INDEX_COMPOSITE_KEY_SIZE \
- BOOST_MULTI_INDEX_LIMIT_COMPOSITE_KEY_SIZE
- #else
- #define BOOST_MULTI_INDEX_COMPOSITE_KEY_SIZE 10
- #endif
- /* BOOST_PP_ENUM of BOOST_MULTI_INDEX_COMPOSITE_KEY_SIZE elements */
- #define BOOST_MULTI_INDEX_CK_ENUM(macro,data) \
- BOOST_PP_ENUM(BOOST_MULTI_INDEX_COMPOSITE_KEY_SIZE,macro,data)
- /* BOOST_PP_ENUM_PARAMS of BOOST_MULTI_INDEX_COMPOSITE_KEY_SIZE elements */
- #define BOOST_MULTI_INDEX_CK_ENUM_PARAMS(param) \
- BOOST_PP_ENUM_PARAMS(BOOST_MULTI_INDEX_COMPOSITE_KEY_SIZE,param)
- /* if n==0 -> text0
- * otherwise -> textn=tuples::null_type
- */
- #define BOOST_MULTI_INDEX_CK_TEMPLATE_PARM(z,n,text) \
- typename BOOST_PP_CAT(text,n) BOOST_PP_EXPR_IF(n,=tuples::null_type)
- /* const textn& kn=textn() */
- #define BOOST_MULTI_INDEX_CK_CTOR_ARG(z,n,text) \
- const BOOST_PP_CAT(text,n)& BOOST_PP_CAT(k,n) = BOOST_PP_CAT(text,n)()
- /* typename list(0)<list(1),n>::type */
- #define BOOST_MULTI_INDEX_CK_APPLY_METAFUNCTION_N(z,n,list) \
- BOOST_DEDUCED_TYPENAME BOOST_PP_LIST_AT(list,0)< \
- BOOST_PP_LIST_AT(list,1),n \
- >::type
- namespace boost{
- template<class T> class reference_wrapper; /* fwd decl. */
- namespace multi_index{
- namespace detail{
- /* n-th key extractor of a composite key */
- template<typename CompositeKey,int N>
- struct nth_key_from_value
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename mpl::eval_if_c<
- N<tuples::length<key_extractor_tuple>::value,
- tuples::element<N,key_extractor_tuple>,
- mpl::identity<tuples::null_type>
- >::type type;
- };
- /* nth_composite_key_##name<CompositeKey,N>::type yields
- * functor<nth_key_from_value<CompositeKey,N> >, or tuples::null_type
- * if N exceeds the length of the composite key.
- */
- #define BOOST_MULTI_INDEX_CK_NTH_COMPOSITE_KEY_FUNCTOR(name,functor) \
- template<typename KeyFromValue> \
- struct BOOST_PP_CAT(key_,name) \
- { \
- typedef functor<typename KeyFromValue::result_type> type; \
- }; \
- \
- template<> \
- struct BOOST_PP_CAT(key_,name)<tuples::null_type> \
- { \
- typedef tuples::null_type type; \
- }; \
- \
- template<typename CompositeKey,int N> \
- struct BOOST_PP_CAT(nth_composite_key_,name) \
- { \
- typedef typename nth_key_from_value<CompositeKey,N>::type key_from_value; \
- typedef typename BOOST_PP_CAT(key_,name)<key_from_value>::type type; \
- };
- /* nth_composite_key_equal_to
- * nth_composite_key_less
- * nth_composite_key_greater
- * nth_composite_key_hash
- */
- BOOST_MULTI_INDEX_CK_NTH_COMPOSITE_KEY_FUNCTOR(equal_to,std::equal_to)
- BOOST_MULTI_INDEX_CK_NTH_COMPOSITE_KEY_FUNCTOR(less,std::less)
- BOOST_MULTI_INDEX_CK_NTH_COMPOSITE_KEY_FUNCTOR(greater,std::greater)
- BOOST_MULTI_INDEX_CK_NTH_COMPOSITE_KEY_FUNCTOR(hash,boost::hash)
- /* used for defining equality and comparison ops of composite_key_result */
- #define BOOST_MULTI_INDEX_CK_IDENTITY_ENUM_MACRO(z,n,text) text
- struct generic_operator_equal
- {
- template<typename T,typename Q>
- bool operator()(const T& x,const Q& y)const{return x==y;}
- };
- typedef tuple<
- BOOST_MULTI_INDEX_CK_ENUM(
- BOOST_MULTI_INDEX_CK_IDENTITY_ENUM_MACRO,
- detail::generic_operator_equal)> generic_operator_equal_tuple;
- struct generic_operator_less
- {
- template<typename T,typename Q>
- bool operator()(const T& x,const Q& y)const{return x<y;}
- };
- typedef tuple<
- BOOST_MULTI_INDEX_CK_ENUM(
- BOOST_MULTI_INDEX_CK_IDENTITY_ENUM_MACRO,
- detail::generic_operator_less)> generic_operator_less_tuple;
- /* Metaprogramming machinery for implementing equality, comparison and
- * hashing operations of composite_key_result.
- *
- * equal_* checks for equality between composite_key_results and
- * between those and tuples, accepting a tuple of basic equality functors.
- * compare_* does lexicographical comparison.
- * hash_* computes a combination of elementwise hash values.
- */
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename EqualCons
- >
- struct equal_ckey_ckey; /* fwd decl. */
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename EqualCons
- >
- struct equal_ckey_ckey_terminal
- {
- static bool compare(
- const KeyCons1&,const Value1&,
- const KeyCons2&,const Value2&,
- const EqualCons&)
- {
- return true;
- }
- };
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename EqualCons
- >
- struct equal_ckey_ckey_normal
- {
- static bool compare(
- const KeyCons1& c0,const Value1& v0,
- const KeyCons2& c1,const Value2& v1,
- const EqualCons& eq)
- {
- if(!eq.get_head()(c0.get_head()(v0),c1.get_head()(v1)))return false;
- return equal_ckey_ckey<
- BOOST_DEDUCED_TYPENAME KeyCons1::tail_type,Value1,
- BOOST_DEDUCED_TYPENAME KeyCons2::tail_type,Value2,
- BOOST_DEDUCED_TYPENAME EqualCons::tail_type
- >::compare(c0.get_tail(),v0,c1.get_tail(),v1,eq.get_tail());
- }
- };
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename EqualCons
- >
- struct equal_ckey_ckey:
- mpl::if_<
- mpl::or_<
- is_same<KeyCons1,tuples::null_type>,
- is_same<KeyCons2,tuples::null_type>
- >,
- equal_ckey_ckey_terminal<KeyCons1,Value1,KeyCons2,Value2,EqualCons>,
- equal_ckey_ckey_normal<KeyCons1,Value1,KeyCons2,Value2,EqualCons>
- >::type
- {
- };
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename EqualCons
- >
- struct equal_ckey_cval; /* fwd decl. */
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename EqualCons
- >
- struct equal_ckey_cval_terminal
- {
- static bool compare(
- const KeyCons&,const Value&,const ValCons&,const EqualCons&)
- {
- return true;
- }
- static bool compare(
- const ValCons&,const KeyCons&,const Value&,const EqualCons&)
- {
- return true;
- }
- };
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename EqualCons
- >
- struct equal_ckey_cval_normal
- {
- static bool compare(
- const KeyCons& c,const Value& v,const ValCons& vc,
- const EqualCons& eq)
- {
- if(!eq.get_head()(c.get_head()(v),vc.get_head()))return false;
- return equal_ckey_cval<
- BOOST_DEDUCED_TYPENAME KeyCons::tail_type,Value,
- BOOST_DEDUCED_TYPENAME ValCons::tail_type,
- BOOST_DEDUCED_TYPENAME EqualCons::tail_type
- >::compare(c.get_tail(),v,vc.get_tail(),eq.get_tail());
- }
- static bool compare(
- const ValCons& vc,const KeyCons& c,const Value& v,
- const EqualCons& eq)
- {
- if(!eq.get_head()(vc.get_head(),c.get_head()(v)))return false;
- return equal_ckey_cval<
- BOOST_DEDUCED_TYPENAME KeyCons::tail_type,Value,
- BOOST_DEDUCED_TYPENAME ValCons::tail_type,
- BOOST_DEDUCED_TYPENAME EqualCons::tail_type
- >::compare(vc.get_tail(),c.get_tail(),v,eq.get_tail());
- }
- };
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename EqualCons
- >
- struct equal_ckey_cval:
- mpl::if_<
- mpl::or_<
- is_same<KeyCons,tuples::null_type>,
- is_same<ValCons,tuples::null_type>
- >,
- equal_ckey_cval_terminal<KeyCons,Value,ValCons,EqualCons>,
- equal_ckey_cval_normal<KeyCons,Value,ValCons,EqualCons>
- >::type
- {
- };
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename CompareCons
- >
- struct compare_ckey_ckey; /* fwd decl. */
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename CompareCons
- >
- struct compare_ckey_ckey_terminal
- {
- static bool compare(
- const KeyCons1&,const Value1&,
- const KeyCons2&,const Value2&,
- const CompareCons&)
- {
- return false;
- }
- };
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename CompareCons
- >
- struct compare_ckey_ckey_normal
- {
- static bool compare(
- const KeyCons1& c0,const Value1& v0,
- const KeyCons2& c1,const Value2& v1,
- const CompareCons& comp)
- {
- if(comp.get_head()(c0.get_head()(v0),c1.get_head()(v1)))return true;
- if(comp.get_head()(c1.get_head()(v1),c0.get_head()(v0)))return false;
- return compare_ckey_ckey<
- BOOST_DEDUCED_TYPENAME KeyCons1::tail_type,Value1,
- BOOST_DEDUCED_TYPENAME KeyCons2::tail_type,Value2,
- BOOST_DEDUCED_TYPENAME CompareCons::tail_type
- >::compare(c0.get_tail(),v0,c1.get_tail(),v1,comp.get_tail());
- }
- };
- template
- <
- typename KeyCons1,typename Value1,
- typename KeyCons2, typename Value2,
- typename CompareCons
- >
- struct compare_ckey_ckey:
- mpl::if_<
- mpl::or_<
- is_same<KeyCons1,tuples::null_type>,
- is_same<KeyCons2,tuples::null_type>
- >,
- compare_ckey_ckey_terminal<KeyCons1,Value1,KeyCons2,Value2,CompareCons>,
- compare_ckey_ckey_normal<KeyCons1,Value1,KeyCons2,Value2,CompareCons>
- >::type
- {
- };
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename CompareCons
- >
- struct compare_ckey_cval; /* fwd decl. */
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename CompareCons
- >
- struct compare_ckey_cval_terminal
- {
- static bool compare(
- const KeyCons&,const Value&,const ValCons&,const CompareCons&)
- {
- return false;
- }
- static bool compare(
- const ValCons&,const KeyCons&,const Value&,const CompareCons&)
- {
- return false;
- }
- };
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename CompareCons
- >
- struct compare_ckey_cval_normal
- {
- static bool compare(
- const KeyCons& c,const Value& v,const ValCons& vc,
- const CompareCons& comp)
- {
- if(comp.get_head()(c.get_head()(v),vc.get_head()))return true;
- if(comp.get_head()(vc.get_head(),c.get_head()(v)))return false;
- return compare_ckey_cval<
- BOOST_DEDUCED_TYPENAME KeyCons::tail_type,Value,
- BOOST_DEDUCED_TYPENAME ValCons::tail_type,
- BOOST_DEDUCED_TYPENAME CompareCons::tail_type
- >::compare(c.get_tail(),v,vc.get_tail(),comp.get_tail());
- }
- static bool compare(
- const ValCons& vc,const KeyCons& c,const Value& v,
- const CompareCons& comp)
- {
- if(comp.get_head()(vc.get_head(),c.get_head()(v)))return true;
- if(comp.get_head()(c.get_head()(v),vc.get_head()))return false;
- return compare_ckey_cval<
- BOOST_DEDUCED_TYPENAME KeyCons::tail_type,Value,
- BOOST_DEDUCED_TYPENAME ValCons::tail_type,
- BOOST_DEDUCED_TYPENAME CompareCons::tail_type
- >::compare(vc.get_tail(),c.get_tail(),v,comp.get_tail());
- }
- };
- template
- <
- typename KeyCons,typename Value,
- typename ValCons,typename CompareCons
- >
- struct compare_ckey_cval:
- mpl::if_<
- mpl::or_<
- is_same<KeyCons,tuples::null_type>,
- is_same<ValCons,tuples::null_type>
- >,
- compare_ckey_cval_terminal<KeyCons,Value,ValCons,CompareCons>,
- compare_ckey_cval_normal<KeyCons,Value,ValCons,CompareCons>
- >::type
- {
- };
- template<typename KeyCons,typename Value,typename HashCons>
- struct hash_ckey; /* fwd decl. */
- template<typename KeyCons,typename Value,typename HashCons>
- struct hash_ckey_terminal
- {
- static std::size_t hash(
- const KeyCons&,const Value&,const HashCons&,std::size_t carry)
- {
- return carry;
- }
- };
- template<typename KeyCons,typename Value,typename HashCons>
- struct hash_ckey_normal
- {
- static std::size_t hash(
- const KeyCons& c,const Value& v,const HashCons& h,std::size_t carry=0)
- {
- /* same hashing formula as boost::hash_combine */
- carry^=h.get_head()(c.get_head()(v))+0x9e3779b9+(carry<<6)+(carry>>2);
- return hash_ckey<
- BOOST_DEDUCED_TYPENAME KeyCons::tail_type,Value,
- BOOST_DEDUCED_TYPENAME HashCons::tail_type
- >::hash(c.get_tail(),v,h.get_tail(),carry);
- }
- };
- template<typename KeyCons,typename Value,typename HashCons>
- struct hash_ckey:
- mpl::if_<
- is_same<KeyCons,tuples::null_type>,
- hash_ckey_terminal<KeyCons,Value,HashCons>,
- hash_ckey_normal<KeyCons,Value,HashCons>
- >::type
- {
- };
- template<typename ValCons,typename HashCons>
- struct hash_cval; /* fwd decl. */
- template<typename ValCons,typename HashCons>
- struct hash_cval_terminal
- {
- static std::size_t hash(const ValCons&,const HashCons&,std::size_t carry)
- {
- return carry;
- }
- };
- template<typename ValCons,typename HashCons>
- struct hash_cval_normal
- {
- static std::size_t hash(
- const ValCons& vc,const HashCons& h,std::size_t carry=0)
- {
- carry^=h.get_head()(vc.get_head())+0x9e3779b9+(carry<<6)+(carry>>2);
- return hash_cval<
- BOOST_DEDUCED_TYPENAME ValCons::tail_type,
- BOOST_DEDUCED_TYPENAME HashCons::tail_type
- >::hash(vc.get_tail(),h.get_tail(),carry);
- }
- };
- template<typename ValCons,typename HashCons>
- struct hash_cval:
- mpl::if_<
- is_same<ValCons,tuples::null_type>,
- hash_cval_terminal<ValCons,HashCons>,
- hash_cval_normal<ValCons,HashCons>
- >::type
- {
- };
- } /* namespace multi_index::detail */
- /* composite_key_result */
- #if defined(BOOST_MSVC)
- #pragma warning(push)
- #pragma warning(disable:4512)
- #endif
- template<typename CompositeKey>
- struct composite_key_result
- {
- typedef CompositeKey composite_key_type;
- typedef typename composite_key_type::value_type value_type;
- composite_key_result(
- const composite_key_type& composite_key_,const value_type& value_):
- composite_key(composite_key_),value(value_)
- {}
- const composite_key_type& composite_key;
- const value_type& value;
- };
- #if defined(BOOST_MSVC)
- #pragma warning(pop)
- #endif
- /* composite_key */
- template<
- typename Value,
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_TEMPLATE_PARM,KeyFromValue)
- >
- struct composite_key:
- private tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(KeyFromValue)>
- {
- private:
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(KeyFromValue)> super;
- public:
- typedef super key_extractor_tuple;
- typedef Value value_type;
- typedef composite_key_result<composite_key> result_type;
- composite_key(
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_CTOR_ARG,KeyFromValue)):
- super(BOOST_MULTI_INDEX_CK_ENUM_PARAMS(k))
- {}
- composite_key(const key_extractor_tuple& x):super(x){}
- const key_extractor_tuple& key_extractors()const{return *this;}
- key_extractor_tuple& key_extractors(){return *this;}
- template<typename ChainedPtr>
- #if !defined(BOOST_NO_SFINAE)
- typename disable_if<
- is_convertible<const ChainedPtr&,const value_type&>,result_type>::type
- #else
- result_type
- #endif
- operator()(const ChainedPtr& x)const
- {
- return operator()(*x);
- }
- result_type operator()(const value_type& x)const
- {
- return result_type(*this,x);
- }
- result_type operator()(const reference_wrapper<const value_type>& x)const
- {
- return result_type(*this,x.get());
- }
- result_type operator()(const reference_wrapper<value_type>& x)const
- {
- return result_type(*this,x.get());
- }
- };
- /* comparison operators */
- /* == */
- template<typename CompositeKey1,typename CompositeKey2>
- inline bool operator==(
- const composite_key_result<CompositeKey1>& x,
- const composite_key_result<CompositeKey2>& y)
- {
- typedef typename CompositeKey1::key_extractor_tuple key_extractor_tuple1;
- typedef typename CompositeKey1::value_type value_type1;
- typedef typename CompositeKey2::key_extractor_tuple key_extractor_tuple2;
- typedef typename CompositeKey2::value_type value_type2;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple1>::value==
- tuples::length<key_extractor_tuple2>::value);
- return detail::equal_ckey_ckey<
- key_extractor_tuple1,value_type1,
- key_extractor_tuple2,value_type2,
- detail::generic_operator_equal_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- y.composite_key.key_extractors(),y.value,
- detail::generic_operator_equal_tuple());
- }
- template<
- typename CompositeKey,
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value)
- >
- inline bool operator==(
- const composite_key_result<CompositeKey>& x,
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
-
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple>::value==
- tuples::length<key_tuple>::value);
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,detail::generic_operator_equal_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- y,detail::generic_operator_equal_tuple());
- }
- template
- <
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value),
- typename CompositeKey
- >
- inline bool operator==(
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& x,
- const composite_key_result<CompositeKey>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
-
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple>::value==
- tuples::length<key_tuple>::value);
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,detail::generic_operator_equal_tuple
- >::compare(
- x,y.composite_key.key_extractors(),
- y.value,detail::generic_operator_equal_tuple());
- }
- #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
- !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- template<typename CompositeKey,typename... Values>
- inline bool operator==(
- const composite_key_result<CompositeKey>& x,
- const std::tuple<Values...>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
-
- BOOST_STATIC_ASSERT(
- static_cast<std::size_t>(tuples::length<key_extractor_tuple>::value)==
- std::tuple_size<key_tuple>::value);
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,detail::generic_operator_equal_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- detail::make_cons_stdtuple(y),detail::generic_operator_equal_tuple());
- }
- template<typename CompositeKey,typename... Values>
- inline bool operator==(
- const std::tuple<Values...>& x,
- const composite_key_result<CompositeKey>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
- BOOST_STATIC_ASSERT(
- static_cast<std::size_t>(tuples::length<key_extractor_tuple>::value)==
- std::tuple_size<key_tuple>::value);
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,detail::generic_operator_equal_tuple
- >::compare(
- detail::make_cons_stdtuple(x),y.composite_key.key_extractors(),
- y.value,detail::generic_operator_equal_tuple());
- }
- #endif
- /* < */
- template<typename CompositeKey1,typename CompositeKey2>
- inline bool operator<(
- const composite_key_result<CompositeKey1>& x,
- const composite_key_result<CompositeKey2>& y)
- {
- typedef typename CompositeKey1::key_extractor_tuple key_extractor_tuple1;
- typedef typename CompositeKey1::value_type value_type1;
- typedef typename CompositeKey2::key_extractor_tuple key_extractor_tuple2;
- typedef typename CompositeKey2::value_type value_type2;
- return detail::compare_ckey_ckey<
- key_extractor_tuple1,value_type1,
- key_extractor_tuple2,value_type2,
- detail::generic_operator_less_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- y.composite_key.key_extractors(),y.value,
- detail::generic_operator_less_tuple());
- }
- template
- <
- typename CompositeKey,
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value)
- >
- inline bool operator<(
- const composite_key_result<CompositeKey>& x,
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
-
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,detail::generic_operator_less_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- y,detail::generic_operator_less_tuple());
- }
- template
- <
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value),
- typename CompositeKey
- >
- inline bool operator<(
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& x,
- const composite_key_result<CompositeKey>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
-
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,detail::generic_operator_less_tuple
- >::compare(
- x,y.composite_key.key_extractors(),
- y.value,detail::generic_operator_less_tuple());
- }
- #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
- !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- template<typename CompositeKey,typename... Values>
- inline bool operator<(
- const composite_key_result<CompositeKey>& x,
- const std::tuple<Values...>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
-
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,detail::generic_operator_less_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- detail::make_cons_stdtuple(y),detail::generic_operator_less_tuple());
- }
- template<typename CompositeKey,typename... Values>
- inline bool operator<(
- const std::tuple<Values...>& x,
- const composite_key_result<CompositeKey>& y)
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
-
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,detail::generic_operator_less_tuple
- >::compare(
- detail::make_cons_stdtuple(x),y.composite_key.key_extractors(),
- y.value,detail::generic_operator_less_tuple());
- }
- #endif
- /* rest of comparison operators */
- #define BOOST_MULTI_INDEX_CK_COMPLETE_COMP_OPS(t1,t2,a1,a2) \
- template<t1,t2> inline bool operator!=(const a1& x,const a2& y) \
- { \
- return !(x==y); \
- } \
- \
- template<t1,t2> inline bool operator>(const a1& x,const a2& y) \
- { \
- return y<x; \
- } \
- \
- template<t1,t2> inline bool operator>=(const a1& x,const a2& y) \
- { \
- return !(x<y); \
- } \
- \
- template<t1,t2> inline bool operator<=(const a1& x,const a2& y) \
- { \
- return !(y<x); \
- }
- BOOST_MULTI_INDEX_CK_COMPLETE_COMP_OPS(
- typename CompositeKey1,
- typename CompositeKey2,
- composite_key_result<CompositeKey1>,
- composite_key_result<CompositeKey2>
- )
- BOOST_MULTI_INDEX_CK_COMPLETE_COMP_OPS(
- typename CompositeKey,
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value),
- composite_key_result<CompositeKey>,
- tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>
- )
- BOOST_MULTI_INDEX_CK_COMPLETE_COMP_OPS(
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value),
- typename CompositeKey,
- tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>,
- composite_key_result<CompositeKey>
- )
- #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
- !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- BOOST_MULTI_INDEX_CK_COMPLETE_COMP_OPS(
- typename CompositeKey,
- typename... Values,
- composite_key_result<CompositeKey>,
- std::tuple<Values...>
- )
- BOOST_MULTI_INDEX_CK_COMPLETE_COMP_OPS(
- typename CompositeKey,
- typename... Values,
- std::tuple<Values...>,
- composite_key_result<CompositeKey>
- )
- #endif
- /* composite_key_equal_to */
- template
- <
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_TEMPLATE_PARM,Pred)
- >
- struct composite_key_equal_to:
- private tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Pred)>
- {
- private:
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Pred)> super;
- public:
- typedef super key_eq_tuple;
- composite_key_equal_to(
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_CTOR_ARG,Pred)):
- super(BOOST_MULTI_INDEX_CK_ENUM_PARAMS(k))
- {}
- composite_key_equal_to(const key_eq_tuple& x):super(x){}
- const key_eq_tuple& key_eqs()const{return *this;}
- key_eq_tuple& key_eqs(){return *this;}
- template<typename CompositeKey1,typename CompositeKey2>
- bool operator()(
- const composite_key_result<CompositeKey1> & x,
- const composite_key_result<CompositeKey2> & y)const
- {
- typedef typename CompositeKey1::key_extractor_tuple key_extractor_tuple1;
- typedef typename CompositeKey1::value_type value_type1;
- typedef typename CompositeKey2::key_extractor_tuple key_extractor_tuple2;
- typedef typename CompositeKey2::value_type value_type2;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple1>::value<=
- tuples::length<key_eq_tuple>::value&&
- tuples::length<key_extractor_tuple1>::value==
- tuples::length<key_extractor_tuple2>::value);
- return detail::equal_ckey_ckey<
- key_extractor_tuple1,value_type1,
- key_extractor_tuple2,value_type2,
- key_eq_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- y.composite_key.key_extractors(),y.value,
- key_eqs());
- }
-
- template
- <
- typename CompositeKey,
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value)
- >
- bool operator()(
- const composite_key_result<CompositeKey>& x,
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple>::value<=
- tuples::length<key_eq_tuple>::value&&
- tuples::length<key_extractor_tuple>::value==
- tuples::length<key_tuple>::value);
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,key_eq_tuple
- >::compare(x.composite_key.key_extractors(),x.value,y,key_eqs());
- }
- template
- <
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value),
- typename CompositeKey
- >
- bool operator()(
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& x,
- const composite_key_result<CompositeKey>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
- BOOST_STATIC_ASSERT(
- tuples::length<key_tuple>::value<=
- tuples::length<key_eq_tuple>::value&&
- tuples::length<key_tuple>::value==
- tuples::length<key_extractor_tuple>::value);
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,key_eq_tuple
- >::compare(x,y.composite_key.key_extractors(),y.value,key_eqs());
- }
- #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
- !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- template<typename CompositeKey,typename... Values>
- bool operator()(
- const composite_key_result<CompositeKey>& x,
- const std::tuple<Values...>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple>::value<=
- tuples::length<key_eq_tuple>::value&&
- static_cast<std::size_t>(tuples::length<key_extractor_tuple>::value)==
- std::tuple_size<key_tuple>::value);
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,key_eq_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- detail::make_cons_stdtuple(y),key_eqs());
- }
- template<typename CompositeKey,typename... Values>
- bool operator()(
- const std::tuple<Values...>& x,
- const composite_key_result<CompositeKey>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
- BOOST_STATIC_ASSERT(
- std::tuple_size<key_tuple>::value<=
- static_cast<std::size_t>(tuples::length<key_eq_tuple>::value)&&
- std::tuple_size<key_tuple>::value==
- static_cast<std::size_t>(tuples::length<key_extractor_tuple>::value));
- return detail::equal_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,key_eq_tuple
- >::compare(
- detail::make_cons_stdtuple(x),y.composite_key.key_extractors(),
- y.value,key_eqs());
- }
- #endif
- };
- /* composite_key_compare */
- template
- <
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_TEMPLATE_PARM,Compare)
- >
- struct composite_key_compare:
- private tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Compare)>
- {
- private:
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Compare)> super;
- public:
- typedef super key_comp_tuple;
- composite_key_compare(
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_CTOR_ARG,Compare)):
- super(BOOST_MULTI_INDEX_CK_ENUM_PARAMS(k))
- {}
- composite_key_compare(const key_comp_tuple& x):super(x){}
- const key_comp_tuple& key_comps()const{return *this;}
- key_comp_tuple& key_comps(){return *this;}
- template<typename CompositeKey1,typename CompositeKey2>
- bool operator()(
- const composite_key_result<CompositeKey1> & x,
- const composite_key_result<CompositeKey2> & y)const
- {
- typedef typename CompositeKey1::key_extractor_tuple key_extractor_tuple1;
- typedef typename CompositeKey1::value_type value_type1;
- typedef typename CompositeKey2::key_extractor_tuple key_extractor_tuple2;
- typedef typename CompositeKey2::value_type value_type2;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple1>::value<=
- tuples::length<key_comp_tuple>::value||
- tuples::length<key_extractor_tuple2>::value<=
- tuples::length<key_comp_tuple>::value);
- return detail::compare_ckey_ckey<
- key_extractor_tuple1,value_type1,
- key_extractor_tuple2,value_type2,
- key_comp_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- y.composite_key.key_extractors(),y.value,
- key_comps());
- }
-
- #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
- template<typename CompositeKey,typename Value>
- bool operator()(
- const composite_key_result<CompositeKey>& x,
- const Value& y)const
- {
- return operator()(x,boost::make_tuple(boost::cref(y)));
- }
- #endif
- template
- <
- typename CompositeKey,
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value)
- >
- bool operator()(
- const composite_key_result<CompositeKey>& x,
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple>::value<=
- tuples::length<key_comp_tuple>::value||
- tuples::length<key_tuple>::value<=
- tuples::length<key_comp_tuple>::value);
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,key_comp_tuple
- >::compare(x.composite_key.key_extractors(),x.value,y,key_comps());
- }
- #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
- template<typename Value,typename CompositeKey>
- bool operator()(
- const Value& x,
- const composite_key_result<CompositeKey>& y)const
- {
- return operator()(boost::make_tuple(boost::cref(x)),y);
- }
- #endif
- template
- <
- BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value),
- typename CompositeKey
- >
- bool operator()(
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& x,
- const composite_key_result<CompositeKey>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
- BOOST_STATIC_ASSERT(
- tuples::length<key_tuple>::value<=
- tuples::length<key_comp_tuple>::value||
- tuples::length<key_extractor_tuple>::value<=
- tuples::length<key_comp_tuple>::value);
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- key_tuple,key_comp_tuple
- >::compare(x,y.composite_key.key_extractors(),y.value,key_comps());
- }
- #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
- !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- template<typename CompositeKey,typename... Values>
- bool operator()(
- const composite_key_result<CompositeKey>& x,
- const std::tuple<Values...>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple>::value<=
- tuples::length<key_comp_tuple>::value||
- std::tuple_size<key_tuple>::value<=
- static_cast<std::size_t>(tuples::length<key_comp_tuple>::value));
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,key_comp_tuple
- >::compare(
- x.composite_key.key_extractors(),x.value,
- detail::make_cons_stdtuple(y),key_comps());
- }
- template<typename CompositeKey,typename... Values>
- bool operator()(
- const std::tuple<Values...>& x,
- const composite_key_result<CompositeKey>& y)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
- BOOST_STATIC_ASSERT(
- std::tuple_size<key_tuple>::value<=
- static_cast<std::size_t>(tuples::length<key_comp_tuple>::value)||
- tuples::length<key_extractor_tuple>::value<=
- tuples::length<key_comp_tuple>::value);
- return detail::compare_ckey_cval<
- key_extractor_tuple,value_type,
- cons_key_tuple,key_comp_tuple
- >::compare(
- detail::make_cons_stdtuple(x),y.composite_key.key_extractors(),
- y.value,key_comps());
- }
- #endif
- };
- /* composite_key_hash */
- template
- <
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_TEMPLATE_PARM,Hash)
- >
- struct composite_key_hash:
- private tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Hash)>
- {
- private:
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Hash)> super;
- public:
- typedef super key_hasher_tuple;
- composite_key_hash(
- BOOST_MULTI_INDEX_CK_ENUM(BOOST_MULTI_INDEX_CK_CTOR_ARG,Hash)):
- super(BOOST_MULTI_INDEX_CK_ENUM_PARAMS(k))
- {}
- composite_key_hash(const key_hasher_tuple& x):super(x){}
- const key_hasher_tuple& key_hash_functions()const{return *this;}
- key_hasher_tuple& key_hash_functions(){return *this;}
- template<typename CompositeKey>
- std::size_t operator()(const composite_key_result<CompositeKey> & x)const
- {
- typedef typename CompositeKey::key_extractor_tuple key_extractor_tuple;
- typedef typename CompositeKey::value_type value_type;
- BOOST_STATIC_ASSERT(
- tuples::length<key_extractor_tuple>::value==
- tuples::length<key_hasher_tuple>::value);
- return detail::hash_ckey<
- key_extractor_tuple,value_type,
- key_hasher_tuple
- >::hash(x.composite_key.key_extractors(),x.value,key_hash_functions());
- }
-
- template<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(typename Value)>
- std::size_t operator()(
- const tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)>& x)const
- {
- typedef tuple<BOOST_MULTI_INDEX_CK_ENUM_PARAMS(Value)> key_tuple;
- BOOST_STATIC_ASSERT(
- tuples::length<key_tuple>::value==
- tuples::length<key_hasher_tuple>::value);
- return detail::hash_cval<
- key_tuple,key_hasher_tuple
- >::hash(x,key_hash_functions());
- }
- #if !defined(BOOST_NO_CXX11_HDR_TUPLE)&&\
- !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
- template<typename... Values>
- std::size_t operator()(const std::tuple<Values...>& x)const
- {
- typedef std::tuple<Values...> key_tuple;
- typedef typename detail::cons_stdtuple_ctor<
- key_tuple>::result_type cons_key_tuple;
- BOOST_STATIC_ASSERT(
- std::tuple_size<key_tuple>::value==
- static_cast<std::size_t>(tuples::length<key_hasher_tuple>::value));
- return detail::hash_cval<
- cons_key_tuple,key_hasher_tuple
- >::hash(detail::make_cons_stdtuple(x),key_hash_functions());
- }
- #endif
- };
- /* Instantiations of the former functors with "natural" basic components:
- * composite_key_result_equal_to uses std::equal_to of the values.
- * composite_key_result_less uses std::less.
- * composite_key_result_greater uses std::greater.
- * composite_key_result_hash uses boost::hash.
- */
- #define BOOST_MULTI_INDEX_CK_RESULT_EQUAL_TO_SUPER \
- composite_key_equal_to< \
- BOOST_MULTI_INDEX_CK_ENUM( \
- BOOST_MULTI_INDEX_CK_APPLY_METAFUNCTION_N, \
- /* the argument is a PP list */ \
- (detail::nth_composite_key_equal_to, \
- (BOOST_DEDUCED_TYPENAME CompositeKeyResult::composite_key_type, \
- BOOST_PP_NIL))) \
- >
- template<typename CompositeKeyResult>
- struct composite_key_result_equal_to:
- BOOST_MULTI_INDEX_PRIVATE_IF_USING_DECL_FOR_TEMPL_FUNCTIONS
- BOOST_MULTI_INDEX_CK_RESULT_EQUAL_TO_SUPER
- {
- private:
- typedef BOOST_MULTI_INDEX_CK_RESULT_EQUAL_TO_SUPER super;
- public:
- typedef CompositeKeyResult first_argument_type;
- typedef first_argument_type second_argument_type;
- typedef bool result_type;
- using super::operator();
- };
- #define BOOST_MULTI_INDEX_CK_RESULT_LESS_SUPER \
- composite_key_compare< \
- BOOST_MULTI_INDEX_CK_ENUM( \
- BOOST_MULTI_INDEX_CK_APPLY_METAFUNCTION_N, \
- /* the argument is a PP list */ \
- (detail::nth_composite_key_less, \
- (BOOST_DEDUCED_TYPENAME CompositeKeyResult::composite_key_type, \
- BOOST_PP_NIL))) \
- >
- template<typename CompositeKeyResult>
- struct composite_key_result_less:
- BOOST_MULTI_INDEX_PRIVATE_IF_USING_DECL_FOR_TEMPL_FUNCTIONS
- BOOST_MULTI_INDEX_CK_RESULT_LESS_SUPER
- {
- private:
- typedef BOOST_MULTI_INDEX_CK_RESULT_LESS_SUPER super;
- public:
- typedef CompositeKeyResult first_argument_type;
- typedef first_argument_type second_argument_type;
- typedef bool result_type;
- using super::operator();
- };
- #define BOOST_MULTI_INDEX_CK_RESULT_GREATER_SUPER \
- composite_key_compare< \
- BOOST_MULTI_INDEX_CK_ENUM( \
- BOOST_MULTI_INDEX_CK_APPLY_METAFUNCTION_N, \
- /* the argument is a PP list */ \
- (detail::nth_composite_key_greater, \
- (BOOST_DEDUCED_TYPENAME CompositeKeyResult::composite_key_type, \
- BOOST_PP_NIL))) \
- >
- template<typename CompositeKeyResult>
- struct composite_key_result_greater:
- BOOST_MULTI_INDEX_PRIVATE_IF_USING_DECL_FOR_TEMPL_FUNCTIONS
- BOOST_MULTI_INDEX_CK_RESULT_GREATER_SUPER
- {
- private:
- typedef BOOST_MULTI_INDEX_CK_RESULT_GREATER_SUPER super;
- public:
- typedef CompositeKeyResult first_argument_type;
- typedef first_argument_type second_argument_type;
- typedef bool result_type;
- using super::operator();
- };
- #define BOOST_MULTI_INDEX_CK_RESULT_HASH_SUPER \
- composite_key_hash< \
- BOOST_MULTI_INDEX_CK_ENUM( \
- BOOST_MULTI_INDEX_CK_APPLY_METAFUNCTION_N, \
- /* the argument is a PP list */ \
- (detail::nth_composite_key_hash, \
- (BOOST_DEDUCED_TYPENAME CompositeKeyResult::composite_key_type, \
- BOOST_PP_NIL))) \
- >
- template<typename CompositeKeyResult>
- struct composite_key_result_hash:
- BOOST_MULTI_INDEX_PRIVATE_IF_USING_DECL_FOR_TEMPL_FUNCTIONS
- BOOST_MULTI_INDEX_CK_RESULT_HASH_SUPER
- {
- private:
- typedef BOOST_MULTI_INDEX_CK_RESULT_HASH_SUPER super;
- public:
- typedef CompositeKeyResult argument_type;
- typedef std::size_t result_type;
- using super::operator();
- };
- } /* namespace multi_index */
- } /* namespace boost */
- /* Specializations of std::equal_to, std::less, std::greater and boost::hash
- * for composite_key_results enabling interoperation with tuples of values.
- */
- namespace std{
- template<typename CompositeKey>
- struct equal_to<boost::multi_index::composite_key_result<CompositeKey> >:
- boost::multi_index::composite_key_result_equal_to<
- boost::multi_index::composite_key_result<CompositeKey>
- >
- {
- };
- template<typename CompositeKey>
- struct less<boost::multi_index::composite_key_result<CompositeKey> >:
- boost::multi_index::composite_key_result_less<
- boost::multi_index::composite_key_result<CompositeKey>
- >
- {
- };
- template<typename CompositeKey>
- struct greater<boost::multi_index::composite_key_result<CompositeKey> >:
- boost::multi_index::composite_key_result_greater<
- boost::multi_index::composite_key_result<CompositeKey>
- >
- {
- };
- } /* namespace std */
- namespace boost{
- template<typename CompositeKey>
- struct hash<boost::multi_index::composite_key_result<CompositeKey> >:
- boost::multi_index::composite_key_result_hash<
- boost::multi_index::composite_key_result<CompositeKey>
- >
- {
- };
- } /* namespace boost */
- #undef BOOST_MULTI_INDEX_CK_RESULT_HASH_SUPER
- #undef BOOST_MULTI_INDEX_CK_RESULT_GREATER_SUPER
- #undef BOOST_MULTI_INDEX_CK_RESULT_LESS_SUPER
- #undef BOOST_MULTI_INDEX_CK_RESULT_EQUAL_TO_SUPER
- #undef BOOST_MULTI_INDEX_CK_COMPLETE_COMP_OPS
- #undef BOOST_MULTI_INDEX_CK_IDENTITY_ENUM_MACRO
- #undef BOOST_MULTI_INDEX_CK_NTH_COMPOSITE_KEY_FUNCTOR
- #undef BOOST_MULTI_INDEX_CK_APPLY_METAFUNCTION_N
- #undef BOOST_MULTI_INDEX_CK_CTOR_ARG
- #undef BOOST_MULTI_INDEX_CK_TEMPLATE_PARM
- #undef BOOST_MULTI_INDEX_CK_ENUM_PARAMS
- #undef BOOST_MULTI_INDEX_CK_ENUM
- #undef BOOST_MULTI_INDEX_COMPOSITE_KEY_SIZE
- #endif
|