...one of the most highly regarded and expertly designed C++ library projects in the world.
— Herb Sutter and Andrei Alexandrescu, C++ Coding Standards
"boost/multi_index/key_extractors.hpp"
声明
"boost/multi_index/identity.hpp"
声明
"boost/multi_index/member.hpp"
声明
"boost/multi_index/mem_fun.hpp"
声明
"boost/multi_index/global_fun.hpp"
声明
"boost/multi_index/composite_key.hpp"
声明
"boost/multi_index/key.hpp"
声明
键提取器类被 基于键的索引 用于从 multi_index_container
的元素中获取索引键。一个 CopyConstructible
和 CopyAssignable
的类 KeyFromValue
被称为从类型 Type
进行键提取,如果
KeyFromValue::result_type
已定义,k1(ca)
已定义并且返回一个可转换为 const KeyFromValue::result_type&
的值,k2
是 k1
的拷贝,则 k1(ca)
与 k2(ca)
的值相同,const KeyFromValue
的 k1
、k2
,以及类型为 const Type&
的 ca
。此外,如果满足以下额外条件,KeyFromValue
是一个读/写键提取器
remove_reference_t<KeyFromValue::result_type>
没有被 const
限定。k1(a)
已定义并且返回一个可转换为 KeyFromValue::result_type&
的值,k1(a)
被绑定到与 k1(const_cast<const Type&>(a))
相同的对象,const KeyFromValue
的 k1
和类型为 Type&
的 a
。Boost.MultiIndex 提供了十二种通用键提取器
identity
,member
,const_mem_fun
(以及三个 变体),mem_fun
(以及三个 变体),global_fun
和composite_key
,key
,允许以非常简洁的方式指定上述提取器(除了 identity
)。Boost.MultiIndex 提供的键提取器根据类型 Type
进行模板化,用于提取键,这些键不仅来自类型 Type
的对象,还来自 Boost.Ref 提供的引用包装器,以及指向 Type
(或 Type
的引用包装器)的链式指针:链式指针是任何类型 P
,对于类型为 const P
的对象 p
,
*p
产生一个类型为 Type&
或 boost::reference_wrapper<Type>
的对象,或者*p
产生一个指向 Type
的链式指针,Type&
或 boost::reference_wrapper<Type>
类型的值。
"boost/multi_index/key_extractors.hpp"
声明#include <boost/multi_index/identity.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/multi_index/global_fun.hpp> #include <boost/multi_index/composite_key.hpp>
此头文件包含 Boost.MultiIndex 提供的所有键提取器。
"boost/multi_index/identity.hpp"
声明namespace boost{ namespace multi_index{ template<typename T> struct identity; } // namespace boost::multi_index } // namespace boost
identity
identity
是一个 Key Extractor
,它表现得像一个不做任何事情的恒等函数。
template<typename Type> struct identity { typedef Type result_type; // only provided if const ChainedPtr& is not convertible to const Type& template<typename ChainedPtr> Type& operator()(const ChainedPtr& x)const; const Type& operator()(const Type& x)const; Type& operator()(Type& x)const; // only provided if Type is non-const // only provided if Type is non-const const Type& operator()(const reference_wrapper<const Type>& x)const; // only provided if Type is const Type& operator()( const reference_wrapper<typename remove_const<Type>::type>& x)const; Type& operator()(const reference_wrapper<Type>& x)const; };
identity<Type>
是一个模型
Type
进行读/写 Key Extractor
,reference_wrapper<const Type>
进行 Key Extractor
,reference_wrapper<Type>
进行读/写 Key Extractor
,const Type
的任何 链式指针 进行 Key Extractor
,Type
的任何 链式指针 进行读/写 Key Extractor
。identity
成员template<typename ChainedPtr> Type& operator()(const ChainedPtr& x)const;
要求:ChainedPtr
是一个指向Type
的 链式指针 类型。
返回值: 对x
所指向的对象的引用。
const Type& operator()(const Type& x)const;
返回值: x
。
Type& operator()(Type& x)const;
返回值: x
。
const Type& operator()(const reference_wrapper<const Type>& x)const;
返回值: x.get()
。
Type& operator()(const reference_wrapper<typename remove_const<Type>::type>& x)const;
返回值: x.get()
。
Type& operator()(const reference_wrapper<Type>& x)const;
返回值: x.get()
。
"boost/multi_index/member.hpp"
声明namespace boost{ namespace multi_index{ template<class Class,typename Type,Type Class::*PtrToMember> struct member; template<class Class,typename Type,std::size_t OffsetOfMember> struct member_offset; // deprecated #define BOOST_MULTI_INDEX_MEMBER(Class,Type,MemberName) implementation defined } // namespace boost::multi_index } // namespace boost
member
member
是一个 Key Extractor
,用于访问类的给定成员。
template<class Class,typename Type,Type Class::*PtrToMember> struct member { typedef Type result_type; // only provided if const ChainedPtr& is not convertible to const Class& template<typename ChainedPtr> Type& operator()(const ChainedPtr& x)const; const Type& operator()(const Class& x)const; Type& operator()(Class& x)const; // only provided if Type is non-const const Type& operator()(const reference_wrapper<const Class>& x)const; Type& operator()(const reference_wrapper<Class>& x)const; };
PtrToMember
模板参数指定了要提取的成员的特定 Type Class::*
指针。member<Class,Type,PtrToMember>
是一个模型
Class
进行 Key Extractor
,如果 Type
不是 const
限定的,则是读/写;reference_wrapper<const Class>
进行 Key Extractor
;reference_wrapper<Class>
进行 Key Extractor
,如果 Type
不是 const
限定的,则是读/写;const Class
的任何 链式指针 进行 Key Extractor
;Class
的任何 链式指针 进行 Key Extractor
,如果 Type
不是 const
限定的,则是读/写。member
成员template<typename ChainedPtr> Type& operator()(const ChainedPtr& x)const;
要求:ChainedPtr
是一个指向Type
的 链式指针 类型。
返回值: 对x
所指向的对象的引用。
const Type& operator()(const Class& x)const;
返回值: x.*PtrToMember
。
Type& operator()(Class& x)const;
返回值: x.*PtrToMember
。
const Type& operator()(const reference_wrapper<const Class>& x)const;
返回值: x.get().*PtrToMember
。
Type& operator()(const reference_wrapper<Class>& x)const;
返回值: x.get().*PtrToMember
。
member_offset
member_offset
是为了克服某些旧版编译器的限制而设计的,目前已弃用。有关更多信息,请参阅 Boost.MultiIndex 的 先前版本。
BOOST_MULTI_INDEX_MEMBER
BOOST_MULTI_INDEX_MEMBER(Class,Type,MemberName)
此宏被设计为一种可移植性机制,用于旧版编译器,这些编译器不支持 member
。因此,在现代环境中不再需要它,尽管一些用户可能仍然因为它提供了稍微简洁的语法而更倾向于使用它而不是直接使用 member
。
"boost/multi_index/mem_fun.hpp"
声明namespace boost{ namespace multi_index{ template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()const> struct const_mem_fun; template< class Class,typename Type,Type (Class::*PtrToMemberFunction)()const volatile > struct cv_mem_fun; template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()const&> struct cref_mem_fun; template< class Class,typename Type,Type (Class::*PtrToMemberFunction)()const volatile& > struct cvref_mem_fun; template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()> struct mem_fun; template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()volatile> struct volatile_mem_fun; template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()&> struct ref_mem_fun; template< class Class,typename Type,Type (Class::*PtrToMemberFunction)()volatile& > struct vref_mem_fun; template< class Class,typename Type, typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction > struct const_mem_fun_explicit; // deprecated template< class Class,typename Type, typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction > struct mem_fun_explicit; // deprecated #define BOOST_MULTI_INDEX_CONST_MEM_FUN(Class,Type,MemberFunName) \ implementation defined #define BOOST_MULTI_INDEX_MEM_FUN(Class,Type,MemberFunName) \ implementation defined } // namespace boost::multi_index } // namespace boost
const_mem_fun
const_mem_fun
是一个 Key Extractor
,它返回通过调用类的给定常量成员函数所产生的结果作为键。
template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()const> struct const_mem_fun { typedef typename remove_reference<Type>::type result_type; // only provided if const ChainedPtr& is not convertible to const Class& template<typename ChainedPtr> Type operator()(const ChainedPtr& x)const; Type operator()(const Class& x)const; Type operator()(const reference_wrapper<const Class>& x)const; Type operator()(const reference_wrapper<Class>& x)const; };
PtrToMemberFunction
模板参数指定了用于提取的常量成员函数的特定 Type (Class::*PtrToMemberFunction)()const
指针。const_mem_fun<Class,Type,PtrToMemberFunction>
是一个模型
Key Extractor
从 Class
;reference_wrapper<const Class>
进行 Key Extractor
;Key Extractor
从 reference_wrapper<Class>
;const Class
的任何 链式指针 进行 Key Extractor
;Key Extractor
从指向 Class
的任何 链式指针;Type
是指向非 const
限定类型的左值引用,它也是读/写的。const_mem_fun
成员template<typename ChainedPtr> Type operator()(const ChainedPtr& x)const;
要求:ChainedPtr
是一个指向Type
的 链式指针 类型。
返回值:(y.*PtrToMemberFunction)()
,其中y
是x
所指向的对象。
Type operator()(const Class& x)const;
返回值: (x.*PtrToMemberFunction)()
。
Type operator()(const reference_wrapper<const Class>& x)const;
返回值: (x.get().*PtrToMemberFunction)()
。
Type operator()(const reference_wrapper<Class>& x)const;
返回值: (x.get().*PtrToMemberFunction)()
。
cv_mem_fun
, cref_mem_fun
和 cvref_mem_fun
这些 Key Extractors
是 const_mem_fun
的变体,用于在传递的成员函数是
const volatile
(cv_mem_fun
)时;const &
限定(cref_mem_fun
)时;const volatile &
限定(cvref_mem_fun
)时。const_mem_fun
完全相同。mem_fun
mem_fun
是一个 Key Extractor
,它返回通过调用类的给定成员函数所产生的结果作为键。
template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()> struct mem_fun { typedef typename remove_reference<Type>::type result_type; // only provided if ChainedPtr& is not convertible to Class& template<typename ChainedPtr> Type operator()(const ChainedPtr& x)const; Type operator()(Class& x)const; Type operator()(const reference_wrapper<Class>& x)const; };
PtrToMemberFunction
模板参数指定了用于提取的成员函数的特定 Type (Class::*PtrToMemberFunction)()
指针。mem_fun<Class,Type,PtrToMemberFunction>
是一个模型
Key Extractor
从 reference_wrapper<Class>
;Key Extractor
从指向 Class
的任何 链式指针;Type
是指向非 const
限定类型的左值引用,它也是读/写的。mem_fun
成员template<typename ChainedPtr> Type operator()(const ChainedPtr& x)const;
要求:ChainedPtr
是一个指向Type
的 链式指针 类型。
返回值:(y.*PtrToMemberFunction)()
,其中y
是x
所指向的对象。
Type operator()(Class& x)const;
返回值: (x.*PtrToMemberFunction)()
。
Type operator()(const reference_wrapper<Class>& x)const;
返回值: (x.get().*PtrToMemberFunction)()
。
volatile_mem_fun
, ref_mem_fun
和 vref_mem_fun
这些 Key Extractors
是 mem_fun
的变体,用于在传递的成员函数是
volatile
(volatile_mem_fun
)时;&
限定(ref_mem_fun
)时;volatile &
限定(vref_mem_fun
)时。mem_fun
完全相同。const_mem_fun_explicit
和 mem_fun_explicit
这些提取器是为了解决 MSVC++ 6.0 的问题而提供的,现在已弃用。有关更多信息,请参阅 Boost.MultiIndex 的 先前版本。
BOOST_MULTI_INDEX_CONST_MEM_FUN
和 BOOST_MULTI_INDEX_MEM_FUN
BOOST_MULTI_INDEX_CONST_MEM_FUN(Class,Type,MemberFunName) BOOST_MULTI_INDEX_MEM_FUN(Class,Type,MemberFunName)
用于使用 const_mem_fun
和 mem_fun
的可移植性宏。虽然现代编译器不再需要它们,但一些用户可能仍会选择使用它们,因为它们提供了稍微简洁的语法。
"boost/multi_index/global_fun.hpp"
声明namespace boost{ namespace multi_index{ template<class Value,typename Type,Type (*PtrToFunction)(Value)> struct global_fun; } // namespace boost::multi_index } // namespace boost
global_fun
global_fun
是一个 Key Extractor
,它基于一个给定的全局或静态成员函数,该函数接受基类型作为参数并返回关联的键。
template<class Value,typename Type,Type (*PtrToFunction)(Value)> struct global_fun { typedef typename remove_reference<Type>::type result_type; // Only provided under the following circumstances: // - If Value is a reference to a constant type, only provided // when const ChainedPtr& is not convertible to Value; // - if Value is a reference to a non-const type, only provided // when ChainedPtr& is not convertible to Value; // - else, only provided when const ChainedPtr& is not // convertible to const Value&. Type operator()(const ChainedPtr& x)const; // only provided if Value is a reference type Type operator()(Value x)const; // only provided if Value is not a reference type Type operator()(const Value& x)const; // only provided if Value is not a reference type Type operator()(const reference_wrapper<const Value>& x)const; // only provided if Value is a reference type Type operator()( const reference_wrapper< remove_reference<Value>::type>& x)const; // only provided if Value is not a reference type or is // a reference to a constant type Type operator()( const reference_wrapper< typename remove_const< typename remove_reference<Value>::type>::type>& x)const; };
PtrToFunction
指定了用于从某个 BaseType
中提取类型为 Type
的键的特定函数。global_fun
支持以下函数签名
Type f(BaseType)
(Value
为 BaseType
);Type f(const BaseType&)
(Value
为 const BaseType&
);Type f(BaseType&)
(Value
为 BaseType&
)。global_fun<Type,Value,PtrToFunction>
是一个模型Key Extractor
从 reference_wrapper<BaseType>
;Key Extractor
从指向 BaseType
的任何 链式指针。Value
为 BaseType
或 const BaseType&
时,global_fun<Type,Value,PtrToFunction>
也是一个模型Key Extractor
从 BaseType
;Key Extractor
从 reference_wrapper<const BaseType>
;Key Extractor
从指向 const BaseType
的任何 链式指针。Type
是指向非 const
限定类型的左值引用,global_fun<Type,Value,PtrToFunction>
也是读/写的。global_fun
成员template<typename ChainedPtr> Type operator()(const ChainedPtr& x)const;
要求:ChainedPtr
是一个指向Value
的 链式指针 类型。
返回值:PtrToFunction)(y)
,其中y
是x
所指向的对象。
Type operator()(Value x)const;
返回值: PtrToFunction(x)
。
Type operator()(const Value& x)const;
返回值: PtrToFunction(x)
。
Type operator()(const reference_wrapper<const Value>& x)const;
返回值: PtrToFunction(x.get())
。
Type operator()(
const reference_wrapper<remove_reference<Value>::type>& x)const;
返回值: PtrToFunction(x.get())
。
Type operator()(
const reference_wrapper<
typename remove_const<
typename remove_reference<Value>::type>::type>& x)const;
返回值: PtrToFunction(x.get())
。
"boost/multi_index/composite_key.hpp"
声明namespace boost{ namespace multi_index{ template<typename Value,typename KeyFromValue0,...,typename KeyFromValuen> struct composite_key; template<typename CompositeKey> struct composite_key_result; // comparison operators for composite_key_result: // OP is any of ==,<,!=,>,>=,<= template<typename CompositeKey1,typename CompositeKey2> bool operator OP( const composite_key_result<CompositeKey1>& x, const composite_key_result<CompositeKey2>& y); template<typename CompositeKey,typename... Values> bool operator OP( const composite_key_result<CompositeKey>& x, const std::tuple<Values...>& y); template<typename CompositeKey,typename... Values> bool operator OP( const std::tuple<Values...>& x, const composite_key_result<CompositeKey>& y); template<typename CompositeKey,typename Value0,...,typename Valuen> bool operator OP( const composite_key_result<CompositeKey>& x, const boost::tuple<Value0,...,Valuen>& y); template<typename Value0,...,typename Valuen,typename CompositeKey> bool operator OP( const boost::tuple<Value0,...,Valuen>& x, const composite_key_result<CompositeKey>& y); // equality functors: template<typename Pred0,...,typename Predn> struct composite_key_equal_to; template<typename CompositeKeyResult> struct composite_key_result_equal_to; // deprecated // comparison functors: template<typename Compare0,...,typename Comparen> struct composite_key_compare; template<typename CompositeKeyResult> struct composite_key_result_less; // deprecated template<typename CompositeKeyResult> struct composite_key_result_greater; // deprecated // hash functors: template<typename Hash0,...,typename Hashn> struct composite_key_hash; template<typename CompositeKeyResult> struct composite_key_result_hash; // deprecated } // namespace boost::multi_index } // namespace boost // specializations of external functors for composite_key_result: namespace std{ template<typename CompositeKey> struct equal_to<boost::multi_index::composite_key_result<CompositeKey> >; template<typename CompositeKey> struct less<boost::multi_index::composite_key_result<CompositeKey> >; template<typename CompositeKey> struct greater<boost::multi_index::composite_key_result<CompositeKey> >; } // namespace std namespace boost{ template<typename CompositeKey> struct hash<boost::multi_index::composite_key_result<CompositeKey> >; } // namespace boost
composite_key
composite_key
是一个 Key Extractor
,它返回多个编译时指定的键提取器的组合值。返回的对象类型为 composite_key_result
<composite_key>
。
template<typename Value,typename KeyFromValue0,...,typename KeyFromValuen> struct composite_key { typedef boost::tuple<KeyFromValue0,...,KeyFromValuen> key_extractor_tuple; typedef Value value_type; typedef composite_key_result<composite_key> result_type; composite_key( const KeyFromValue0& k0=KeyFromValue0(), ... const KeyFromValuen& kn=KeyFromValuen()); composite_key(const key_extractor_tuple& x); const key_extractor_tuple& key_extractors()const; key_extractor_tuple& key_extractors() // only provided if const ChainedPtr& is not convertible to const value_type& template<typename ChainedPtr> result_type operator()(const ChainedPtr& x)const; result_type operator()(const value_type& x)const; result_type operator()(const reference_wrapper<const value_type>& x)const; result_type operator()(const reference_wrapper<value_type>& x)const; };
KeyFromValue0
, ... , KeyFromValuen
是组合键的键提取器类型。这些类型中的每一种都必须是 Value
的 Key Extractor
。至少需要提供一个键提取器。composite_key
实例化的最大键提取器数量是实现定义的。composite_key
内部存储了每个组成键提取器的对象。composite_key<Value,KeyFromValue0,...,KeyFromValuen>
是一个模型
Key Extractor
从 Value
;Key Extractor
从 reference_wrapper<const Value>
;Key Extractor
从 reference_wrapper<Value>
;Key Extractor
从指向 const Value
的任何 链式指针;Key Extractor
从指向 Value
的任何 链式指针。composite_key
成员composite_key(
const KeyFromValue0& k0=KeyFromValue0(),
...
const KeyFromValuen& kn=KeyFromValuen());
效果: 构建一个 composite_key
,它存储所提供键提取器对象的副本。
composite_key(const key_extractor_tuple& x);
效果: 构建一个composite_key
,它存储x
中所提供的键提取器对象的副本。
const key_extractor_tuple& key_extractors()const;
返回值: 对包含 composite_key
内部存储的键提取器的元组的常量引用。
key_extractor_tuple& key_extractors();
返回值: 对包含 composite_key
内部存储的键提取器的元组的引用。
template<typename ChainedPtr>
result_type operator()(const ChainedPtr& x)const;
要求:ChainedPtr
是一个指向result_type
的 链式指针 类型。
返回值: 一个result_type
对象,该对象取决于*this
和y
,其中y
是x
所指向的对象。
result_type operator()(const value_type& x)const;
返回值: 一个result_type
对象,该对象取决于*this
和x
。
result_type operator()(const reference_wrapper<const value_type>& x)const;
返回值: 一个result_type
对象,该对象取决于*this
和x.get()
。
result_type operator()(const reference_wrapper<value_type>& x)const;
返回值: 一个result_type
对象,该对象取决于*this
和x.get()
。
composite_key_result
这是一个由 composite_key
实例返回的、作为其提取键的不透明类型。
template<typename CompositeKey> struct composite_key_result { no public interface available }; // comparison: // OP is any of ==,<,!=,>,>=,<= template<typename CompositeKey1,typename CompositeKey2> bool operator OP( const composite_key_result<CompositeKey1>& x, const composite_key_result<CompositeKey2>& y); template<typename CompositeKey,typename... Values> bool operator OP( const composite_key_result<CompositeKey>& x, const std::tuple<Values...>& y); template<typename CompositeKey,typename... Values> bool operator OP( const std::tuple<Values...>& x, const composite_key_result<CompositeKey>& y); template<typename CompositeKey,typename Value0,...,typename Valuen> bool operator OP( const composite_key_result<CompositeKey>& x, const boost::tuple<Value0,...,Valuen>& y); template<typename Value0,...,typename Valuen,typename CompositeKey> bool operator OP( const boost::tuple<Value0,...,Valuen>& x, const composite_key_result<CompositeKey>& y);
CompositeKey
是与 composite_key_result
类型关联的 composite_key
实例。由复合键返回的 composite_key_result
类型对象必须始终被视为临时对象,即不应存储或复制它们。composite_key_result
不保证是 DefaultConstructible
或 CopyAssignable
。每个 composite_key_result<CompositeKey>
类型对象都内部关联到它返回的 CompositeKey
以及已应用于复合键的 CompositeKey::value_type
类型对象。给定一个类型为 composite_key_result<CompositeKey>
的 x
,我们使用以下表示法
ck(x)
是与 x
关联的 CompositeKey
对象,v(x)
是与 x
关联的 CompositeKey::value_type
类型对象,ki(x) = ck(x).key_extractors().get<i>()
,即 ck(x)
的第 i
个键提取器,xi = ki(x)(v(x))
,即由第 i
个键提取器从 v(x)
中提取的键,length(x)
是 ck(x)
的键提取器数量。y
是一个 std::tuple
或 boost::tuple
类型的值,我们定义yi=get<i>(y)
,length(y)
是 y
的元素数量。template<typename CompositeKey1,typename CompositeKey2>
bool operator==(
const composite_key_result<CompositeKey1>& x,
const composite_key_result<CompositeKey2>& y);
template<typename CompositeKey,typename... Values>
bool operator==(
const composite_key_result<CompositeKey>& x,
const std::tuple<Values...>& y);
template<typename CompositeKey,typename... Values>
bool operator==(
const std::tuple<Values...>& x,
const composite_key_result<CompositeKey>& y);
template<typename CompositeKey,typename Value0,...,typename Valuen>
bool operator==(
const composite_key_result<CompositeKey>& x,
const boost::tuple<Value0,...,Valuen>& y);
template<typename Value0,...,typename Valuen,typename CompositeKey>
bool operator==(
const boost::tuple<Value0,...,Valuen>& x,
const composite_key_result<CompositeKey>& y);
要求:length(x)==length(y)
。表达式xi==yi
对所有i
在[0,length(x))
范围内有效。
返回值: 当且仅当复杂度: 进行的键提取操作和比较操作不超过评估上述表达式所必需的操作,从xi==yi
对所有i
在[0,length(x))
范围内成立。i==0
开始。一旦结果确定为false
,评估就会短路。
template<typename CompositeKey1,typename CompositeKey2>
bool operator<(
const composite_key_result<CompositeKey1>& x,
const composite_key_result<CompositeKey2>& y);
template<typename CompositeKey,typename... Values>
bool operator<(
const composite_key_result<CompositeKey>& x,
const std::tuple<Values...>& y);
template<typename CompositeKey,typename... Values>
bool operator<(
const std::tuple<Values...>& x,
const composite_key_result<CompositeKey>& y);
template<typename CompositeKey,typename Value0,...,typename Valuen>
bool operator<(
const composite_key_result<CompositeKey>& x,
const boost::tuple<Value0,...,Valuen>& y);
template<typename Value0,...,typename Valuen,typename CompositeKey>
bool operator<(
const boost::tuple<Value0,...,Valuen>& x,
const composite_key_result<CompositeKey>& y);
要求: 表达式xi<yi
和yi<xi
对所有i
在[0,min(length(x),length(y)))
范围内有效。
返回值: 当且仅当存在某个j
在范围[0,min(length(x),length(y)))
内,使得复杂度: 进行的键提取操作和比较操作不超过评估上述表达式所必需的操作,从!(xi<yi) && !(yi<xi)
对所有i
在[0,j)
范围内成立,
xj<yj
.i==0
开始。一旦结果确定为false
,评估就会短路。
template<typename CompositeKey1,typename CompositeKey2>
bool operator OP(
const composite_key_result<CompositeKey1>& x,
const composite_key_result<CompositeKey2>& y);
template<typename CompositeKey,typename... Values>
bool operator OP(
const composite_key_result<CompositeKey>& x,
const std::tuple<Values...>& y);
template<typename CompositeKey,typename... Values>
bool operator OP(
const std::tuple<Values...>& x,
const composite_key_result<CompositeKey>& y);
template<typename CompositeKey,typename Value0,...,typename Valuen>
bool operator OP(
const composite_key_result<CompositeKey>& x,
const boost::tuple<Value0,...,Valuen>& y);
template<typename Value0,...,typename Valuen,typename CompositeKey>
bool operator OP(
const boost::tuple<Value0,...,Valuen>& x,
const composite_key_result<CompositeKey>& y);
(OP
是 !=
, >
, >=
, <=
中的任何一个。)
要求: 下列表达式对于考虑的特定OP
有效。
返回值: 当且仅当!(x==y)
(OP
为!=
),
y< x
(OP
为>
),
!(x< y)
(OP
为>=
),
!(y< x)
(OP
为<=
).
composite_key_equal_to
composite_key_equal_to
使用内部存储的多个基本相等谓词集合来测试 composite_key_result
实例之间的相等性,以及这些实例与值元组之间的相等性。
template<typename Pred0,...,typename Predn> struct composite_key_equal_to { typedef boost::tuple<Pred0,...,Predn> key_eq_tuple; composite_key_equal_to( const Pred0& p0=Pred0(), ... const Predn& pn=Predn()); composite_key_equal_to(const key_eq_tuple& x); const key_eq_tuple& key_eqs()const; key_eq_tuple& key_eqs(); template<typename CompositeKey1,typename CompositeKey2> bool operator()( const composite_key_result<CompositeKey1> & x, const composite_key_result<CompositeKey2> & y)const; template<typename CompositeKey,typename... Values> bool operator()( const composite_key_result<CompositeKey>& x, const std::tuple<Values...>& y)const; template<typename CompositeKey,typename... Values> bool operator()( const std::tuple<Values...>& x, const composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value0,...,typename Valuen> bool operator()( const composite_key_result<CompositeKey>& x, const boost::tuple<Value0,...,Valuen>& y)const; template<typename Value0,...,typename Valuen,typename CompositeKey> bool operator()( const boost::tuple<Value0,...,Valuen>& x, const composite_key_result<CompositeKey>& y)const; };
Pred0
, ... , Predn
是 composite_key_equal_to
存储的相等二元谓词的类型。这些谓词中的每一个都必须是 CopyConstructible
和 CopyAssignable
。至少需要提供一个相等谓词。composite_key_equal_to
实例化的最大相等谓词数量是实现定义的。composite_key_equal_to
是 CopyConstructible
和 CopyAssignable
。如果每个 Predi
本身是 DefaultConstructible
,它也是 DefaultConstructible
。
请注意,形式上并不要求 Predi
类型以任何确定的方式表现为相等谓词。然而,如果确实如此,composite_key_equal_to
的语义是明确的,如 composite_key_result
语义 部分所述。
在下面的内容中,我们使用与 composite_key_result
相同的 表示法。
composite_key_equal_to
成员composite_key_equal_to(
const Pred0& p0=Pred0(),
...
const Predn& pn=Predn());
效果: 构建一个 composite_key_equal_to
,它存储所提供的相等谓词的副本。
composite_key_equal_to(const key_eq_tuple& x);
效果: 构建一个composite_key_equal_to
,它存储x
中所提供的相等谓词对象的副本。
const key_eq_tuple& key_eqs()const;
返回值: 对包含 composite_key_equal_to
内部存储的相等谓词对象的元组的常量引用。
key_eq_tuple& key_eqs();
返回值: 对包含 composite_key_equal_to
内部存储的相等谓词对象的元组的引用。
template<typename CompositeKey1,typename CompositeKey2>
bool operator()(
const composite_key_result<CompositeKey1> & x,
const composite_key_result<CompositeKey2> & y)const;
template<typename CompositeKey,typename Values...>
bool operator()(
const composite_key_result<CompositeKey>& x,
const std::tuple<Values...>& y)const;
template<typename CompositeKey,typename Values...>
bool operator()(
const std::tuple<Values...>& x,
const composite_key_result<CompositeKey>& y)const;
template<typename CompositeKey,typename Value0,...,typename Valuen>
bool operator()(
const composite_key_result<CompositeKey>& x,
const boost::tuple<Value0,...,Valuen>& y)const;
template<typename Value0,...,typename Valuen,typename CompositeKey>
bool operator()(
const boost::tuple<Value0,...,Valuen>& x,
const composite_key_result<CompositeKey>& y)const;
要求:length(x)==length(y)
。表达式key_eqs().get<i>()(xi,yi)
和key_eqs().get<i>()(yi,xi)
对所有i
在[0,length(x))
范围内有效。
返回值: 当且仅当复杂度: 进行的键提取操作和比较操作不超过评估上述表达式所必需的操作,从key_eqs().get<i>()(xi,yi)
对所有i
在[0,length(x))
范围内成立。
i==0
开始。一旦结果确定为false
,评估就会短路。
composite_key_result_equal_to
已弃用。请使用 std::equal_to<CompositeKeyResult>
。
std::equal_to
对 composite_key
结果的特化
std::equal_to<CompositeKeyResult>
,其中 CompositeKeyResult
是 composite_key_result
的一个实例,表现得像 composite_key_equal_to
的一个特化,其中提供的所有比较谓词都是 std::equal_to
的实例。
namespace std{ template<typename CompositeKey> struct equal_to<boost::multi_index::composite_key_result<CompositeKey> > { typedef boost::multi_index::composite_key_result< CompositeKey> first_argument_type; typedef first_argument_type second_argument_type; typedef bool result_type; template<typename CompositeKey1,typename CompositeKey2> bool operator()( const boost::multi_index::composite_key_result<CompositeKey1> & x, const boost::multi_index::composite_key_result<CompositeKey2> & y)const; template<typename CompositeKey,typename... Values> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const std::tuple<Values...>& y)const; template<typename CompositeKey,typename... Values> bool operator()( const std::tuple<Values...>& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value0,...,typename Valuen> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const boost::tuple<Value0,...,Valuen>& y)const; template<typename Value0,...,typename Valuen,typename CompositeKey> bool operator()( const boost::tuple<Value0,...,Valuen>& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; }; } // namespace std
CompositeKeyResult
必须是 composite_key<KeyFromValue0,...,KeyFromValuen>
类型的某个实例。然后,std::equal_to<CompositeKeyResult>::operator()
等同于 composite_key_equal_to<Pred0,...,Predn>::operator()
,其中
Predi = std::equal_to<KeyFromValuei::result_type>
对所有i = 0,...,n
。
除了 composite_key_equal_to
对 Predi
的要求外,每种类型都必须是 DefaultConstructible
。std::equal_to<CompositeKeyResult>
是 DefaultConstructible
、CopyConstructible
和 CopyAssignable
。
composite_key_compare
composite_key_compare
使用内部存储的多个基本比较谓词集合来比较 composite_key_result
实例之间以及这些实例与值元组之间的关系。
template<typename Compare0,...,typename Comparen> struct composite_key_compare { typedef boost::tuple<Compare0,...,Comparen> key_comp_tuple; composite_key_compare( const Compare0& c0=Compare0(), ... const Comparen& cn=Comparen()); composite_key_compare(const key_comp_tuple& x); const key_comp_tuple& key_comps()const; key_comp_tuple& key_comps(); template<typename CompositeKey1,typename CompositeKey2> bool operator()( const composite_key_result<CompositeKey1> & x, const composite_key_result<CompositeKey2> & y)const; template<typename CompositeKey,typename... Values> bool operator()( const composite_key_result<CompositeKey>& x, const std::tuple<Values...>& y)const; template<typename CompositeKey,typename... Values> bool operator()( const std::tuple<Values...>& x, const composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value0,...,typename Valuen> bool operator()( const composite_key_result<CompositeKey>& x, const boost::tuple<Value0,...,Valuen>& y)const; template<typename Value0,...,typename Valuen,typename CompositeKey> bool operator()( const boost::tuple<Value0,...,Valuen>& x, const composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value> bool operator()( const composite_key_result<CompositeKey>& x,const Value& y)const; template<typename Value,typename CompositeKey> bool operator()( const Value& x,const composite_key_result<CompositeKey>& y)const; };
Compare0
, ... , Comparen
是 composite_key_compare
存储的比较二元谓词的类型。这些谓词中的每一个都必须是 CopyConstructible
和 CopyAssignable
。至少需要提供一个比较谓词。composite_key_compare
实例化的最大比较谓词数量是实现定义的。composite_key_compare
是 CopyConstructible
和 CopyAssignable
。如果每个 Comparei
本身是 DefaultConstructible
,它也是 DefaultConstructible
。
请注意,形式上并不要求 Comparei
类型以任何确定的方式表现为比较谓词。然而,如果确实如此,composite_key_compare
的语义是明确的,如 composite_key_result
语义 部分所述。
在下面的内容中,我们使用与 composite_key_result
相同的 表示法。
composite_key_compare
成员composite_key_compare(
const Compare0& c0=Compare0(),
...
const Comparen& cn=Comparen());
效果: 构建一个 composite_key_compare
,它存储所提供的比较谓词的副本。
composite_key_compare(const key_comp_tuple& x);
效果: 构建一个composite_key_compare
,它存储x
中所提供的比较谓词对象的副本。
const key_comp_tuple& key_comps()const;
返回值: 对包含 composite_key_compare
内部存储的比较谓词对象的元组的常量引用。
key_comp_tuple& key_comps();
返回值: 对包含 composite_key_compare
内部存储的比较谓词对象的元组的引用。
template<typename CompositeKey1,typename CompositeKey2>
bool operator()(
const composite_key_result<CompositeKey1> & x,
const composite_key_result<CompositeKey2> & y)const;
template<typename CompositeKey,typename... Values>
bool operator()(
const composite_key_result<CompositeKey>& x,
const std::tuple<Values...>& y)const;
template<typename CompositeKey,typename... Values>
bool operator()(
const std::tuple<Values...>& x,
const composite_key_result<CompositeKey>& y)const;
template<typename CompositeKey,typename Value0,...,typename Valuen>
bool operator()(
const composite_key_result<CompositeKey>& x,
const boost::tuple<Value0,...,Valuen>& y)const;
template<typename Value0,...,typename Valuen,typename CompositeKey>
bool operator()(
const boost::tuple<Value0,...,Valuen>& x,
const composite_key_result<CompositeKey>& y)const;
要求: 表达式key_comps().get<i>()(xi,yi)
和key_comps().get<i>()(yi,xi)
对所有i
在[0,min(length(x),length(y)))
范围内有效。
返回值: 当且仅当存在某个j
在范围[0,min(length(x),length(y)))
内,使得复杂度: 进行的键提取操作和比较操作不超过评估上述表达式所必需的操作,从!key_comps().get<i>()(xi,yi) && !key_comps().get<i>()(yi,xi)
对所有i
在[0,j)
范围内成立,
key_comps().get<j>()(xj,yj)
.i==0
开始。一旦结果确定为false
,评估就会短路。
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)));
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);
composite_key_result_less
已弃用。请使用 std::less<CompositeKeyResult>
。
composite_key_result_greater
已弃用。请使用 std::greater<CompositeKeyResult>
。
std::less
对 composite_key
结果的特化
std::less<CompositeKeyResult>
,其中 CompositeKeyResult
是 composite_key_result
的一个实例,表现得像 composite_key_compare
的一个特化,其中提供的所有比较谓词都是 std::less
的实例。
namespace std{ template<typename CompositeKey> struct less<boost::multi_index::composite_key_result<CompositeKey> > { typedef boost::multi_index::composite_key_result< CompositeKey> first_argument_type; typedef first_argument_type second_argument_type; typedef bool result_type; template<typename CompositeKey1,typename CompositeKey2> bool operator()( const boost::multi_index::composite_key_result<CompositeKey1> & x, const boost::multi_index::composite_key_result<CompositeKey2> & y)const; template<typename CompositeKey,typename... Values> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const std::tuple<Values...>& y)const; template<typename CompositeKey,typename... Values> bool operator()( const std::tuple<Values...>& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value0,...,typename Valuen> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const boost::tuple<Value0,...,Valuen>& y)const; template<typename Value0,...,typename Valuen,typename CompositeKey> bool operator()( const boost::tuple<Value0,...,Valuen>& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const Value& y)const; template<typename Value,typename CompositeKey> bool operator()( const Value& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; }; } // namespace std
CompositeKeyResult
必须是 composite_key<KeyFromValue0,...,KeyFromValuen>
类型的某个实例。然后,std::less<CompositeKeyResult>::operator()
等同于 composite_key_compare<Compare0,...,Comparen>::operator()
,其中
Comparei = std::less<KeyFromValuei::result_type>
对所有i = 0,...,n
。
除了 composite_key_compare
对 Comparei
的要求外,每种类型都必须是 DefaultConstructible
。std::less<CompositeKeyResult>
是 DefaultConstructible
、CopyConstructible
和 CopyAssignable
。
std::greater
对 composite_key
结果的特化
std::greater<CompositeKeyResult>
,其中 CompositeKeyResult
是 composite_key_result
的一个实例,表现得像 composite_key_compare
的一个特化,其中提供的所有比较谓词都是 std::greater
的实例。
namespace std{ template<typename CompositeKey> struct greater<boost::multi_index::composite_key_result<CompositeKey> > { typedef boost::multi_index::composite_key_result< CompositeKey> first_argument_type; typedef first_argument_type second_argument_type; typedef bool result_type; template<typename CompositeKey1,typename CompositeKey2> bool operator()( const boost::multi_index::composite_key_result<CompositeKey1> & x, const boost::multi_index::composite_key_result<CompositeKey2> & y)const; template<typename CompositeKey,typename... Values> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const std::tuple<Values...>& y)const; template<typename CompositeKey,typename... Values> bool operator()( const std::tuple<Values...>& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value0,...,typename Valuen> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const boost::tuple<Value0,...,Valuen>& y)const; template<typename Value0,...,typename Valuen,typename CompositeKey> bool operator()( const boost::tuple<Value0,...,Valuen>& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; template<typename CompositeKey,typename Value> bool operator()( const boost::multi_index::composite_key_result<CompositeKey>& x, const Value& y)const; template<typename Value,typename CompositeKey> bool operator()( const Value& x, const boost::multi_index::composite_key_result<CompositeKey>& y)const; }; } // namespace std
CompositeKeyResult
必须是 composite_key<KeyFromValue0,...,KeyFromValuen>
类型的某个实例。然后,std::greater<CompositeKeyResult>::operator()
等同于 composite_key_compare<Compare0,...,Comparen>::operator()
,其中
Comparei = std::greater<KeyFromValuei::result_type>
对所有i = 0,...,n
。
除了 composite_key_compare
对 Comparei
的要求外,每种类型都必须是 DefaultConstructible
。std::greater<CompositeKeyResult>
是 DefaultConstructible
、CopyConstructible
和 CopyAssignable
。
composite_key_hash
composite_key_hash
基于一组基本哈希函数对象生成 composite_key_result
实例的哈希值。
template<typename Hash0,...,typename Hashn> struct composite_key_hash { typedef boost::tuple<Hash0,...,Hashn> key_hasher_tuple; composite_key_hash( const Hash0& h0=Hash0(), ... const Hashn& hn=Hashn()); composite_key_hash(const key_hasher_tuple& x); const key_hasher_tuple& key_hash_functions()const; key_hasher_tuple& key_hash_functions(); template<typename CompositeKey> std::size_t operator()( const composite_key_result<CompositeKey>& x)const; template<typename... Values> std::size_t operator()( const std::tuple<Values...>& x)const; template<typename Value0,...,typename Valuen> std::size_t operator()( const boost::tuple<Value0,...,Valuen>& x)const; };
Hash0
, ... , Hashn
是 composite_key_hash
存储的哈希一元函数对象的类型。这些对象中的每一个都必须是 CopyConstructible
和 CopyAssignable
,并且返回一个类型为 std::size_t
且范围在 [0, std::numeric_limits<std::size_t>::max())
) 内的值。至少需要提供一个哈希函数。composite_key_hash
实例化的最大哈希函数数量是实现定义的。composite_key_hash
是 CopyConstructible
和 CopyAssignable
。如果每个 Hashi
本身是 DefaultConstructible
,它也是 DefaultConstructible
。
在下面的内容中,我们使用与 composite_key_result
相同的 表示法。
composite_key_hash
成员composite_key_hash(
const Hash0& h0=Hash0(),
...
const Hashn& hn=Hashn());
效果: 构建一个 composite_key_hash
,它存储所提供的哈希函数对象的副本。
composite_key_hash(const key_hasher_tuple& x);
效果: 构建一个composite_key_hash
,它存储x
中所提供的哈希函数对象的副本。
const key_hasher_tuple& key_hash_functions()const;
返回值: 对包含 composite_key_hash
内部存储的哈希函数对象的元组的常量引用。
key_hasher_tuple& key_hash_functions();
返回值: 对包含 composite_key_hash
内部存储的哈希函数对象的元组的引用。
template<typename CompositeKey>
bool operator()(
const composite_key_result<CompositeKey>& x)const;
template<typename... Values>
bool operator()(
const std::tuple<Values...>& x)const;
template<typename Value0,...,typename Valuen>
bool operator()(
const boost::tuple<Value0,...,Valuen>& x)const;
要求:length(x)==length(key_hash_functions())
。表达式key_hash_functions().get<i>()(xi)
对所有i
在[0,length(x))
范围内有效。
返回值: 一个范围在[0, std::numeric_limits<std::size_t>::max())
内的值,该值仅取决于数值元组(key_hash_functions().get<0>()(x0)
, ... ,key_hash_functions().get<N>()(xN)
),其中N=length(x)-1
。
composite_key_result_hash
已弃用。请使用 boost::hash<CompositeKeyResult>
。
boost::hash
对 composite_key
结果的特化
boost::hash<CompositeKeyResult>
,其中 CompositeKeyResult
是 composite_key_result
的一个实例,表现得像 composite_key_hash
的一个特化,其中提供的所有哈希函数都是 boost::hash
的实例。
namespace boost{ template<typename CompositeKey> struct hash<multi_index::composite_key_result<CompositeKey> > { typedef multi_index::composite_key_result<CompositeKey> argument_type; typedef std::size_t result_type; template<typename CompositeKey> std::size_t operator()( const multi_index::composite_key_result<CompositeKey>& x)const; template<typename... Values> std::size_t operator()( const std::tuple<Values...>& x)const; template<typename Value0,...,typename Valuen> std::size_t operator()( const boost::tuple<Value0,...,Valuen>& x)const; }; } // namespace boost
CompositeKeyResult
必须是 composite_key<KeyFromValue0,...,KeyFromValuen>
类型的某个实例。然后,boost::hash<CompositeKeyResult>::operator()
等同于 composite_key_hash<Hash0,...,Hashn>::operator()
,其中
Hashi = boost::hash<KeyFromValuei::result_type>
对所有i = 0,...,n
。
除了 composite_key_hash
对 Hashi
的要求外,每种类型都必须是 DefaultConstructible
。boost::hash<CompositeKeyResult>
是 DefaultConstructible
、CopyConstructible
和 CopyAssignable
。
composite_key_result
的语义composite_key_result
的相等、比较和哈希操作的设计基于以下原理:composite_key_result
被视为一个“虚拟”元组,它的每个元素都是相应基本键提取器的结果。因此,任何给定的操作都归结为相应元素操作的组合。这种映射保留了基本操作的基本属性;例如,如果基本谓词本身产生等价关系,则定义了一个真正的等价关系。我们可以形式地陈述这些事实如下。
考虑一个 composite_key_equal_to
实例,其类型为 Pred0
, ... , Predn
,使得每个 Predi
在某个类型 Ti
上产生一个等价关系,并且 CompositeKey
是一个类型 composite_key<Value,KeyFromValue0,...,KeyFromValuej>
的形式,其中 j <= n
,使得
那么,KeyFromValuei::result_type = Ti
,对所有i = 0,...,j
。
composite_key_equal_to
在类型为 composite_key_result<CompositeKey>
的对象上产生一个等价关系;如果它们的所有基本键提取器值也等价,则这两个对象是等价的。此外,给定一个 composite_key_hash<Hash0,...,Hashj>
实例,以下类型是 (composite_key_hash
, composite_key_equal_to
) 关于 composite_key_result<CompositeKey>
的 Compatible Keys
前提是每个tuple<Q0,...,Qj>
,
composite_key_result<composite_key<K0,...,Kj> >
,其中Ki::result_type = Qi
对所有i = 0,...,j
。
Qi
要么是 Ti
,要么是 (Hashi
, Predi
) 的 Compatible Key
。至于比较,考虑一个 composite_key_compare
实例,其类型为 Compare0
, ... , Comparen
,使得每个 Comparei
在类型 Ti
上产生一个严格弱序。然后,对于上面定义的 CompositeKey
类型,composite_key_compare
在类型为 composite_key_result<CompositeKey>
的对象上产生一个严格弱序,并且诱导的顺序是字典序。此外,以下类型是 composite_key_compare
关于 composite_key_result<CompositeKey>
的 Compatible Keys
前提是tuple<Q0,...,Qk>
,k <= n
composite_key_result<composite_key<K0,...,Kk> >
, 其中Ki::result_type = Qi
对所有i = 0,...,k
。
i = 0,...,min(j,k)-1
,Qi
要么是 Ti
,要么不比 Ti
更粗糙(Qi
是 Comparei
的 Compatible Key
,并且没有两个不同的 Ti
元素等价于一个单一的 Qi
元素);Qm
(其中 m = min(j,k)
)要么是 Tm
,要么是 Comparem
的 Compatible Key
。1+min(j,k)
个元素上进行字典序比较。composite_key_result
的相等和比较运算符也具有类似的属性。但请注意,相等性仅对相同长度的对象定义,而比较则考虑操作数的最小长度。因此,x==y
诱导的等价类是与 !(x<y)&&!(y<x)
关联的等价类的子集。
"boost/multi_index/key.hpp"
声明#include <boost/multi_index/member.hpp> #include <boost/multi_index/mem_fun.hpp> #include <boost/multi_index/global_fun.hpp> #include <boost/multi_index/composite_key.hpp> #if implementation defined /* auto non-type template parameters supported */ #define BOOST_MULTI_INDEX_KEY_SUPPORTED namespace boost{ namespace multi_index{ template<auto... Keys> using key=implementation defined; } /* namespace multi_index */ } /* namespace boost */ #endif
key
在支持 C++17 的环境中,key
为 Boost.MultiIndex 预定义键提取器的规范提供了非常简洁的语法。传递给 key
的模板参数数量必须大于零且不超过 composite_key
所接受的最大键提取器数量。key<Key>
解析为
member<Class,Type,Key>
,如果 Key
的类型是 Type Class::*
;const_mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()const
(带或不带 noexcept
说明符);cv_mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()const volatile
(带或不带 noexcept
说明符);cref_mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()const&
(带或不带 noexcept
说明符);cvref_mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()const volatile&
(带或不带 noexcept
说明符);mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()
(带或不带 noexcept
说明符);volatile_mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()volatile
(带或不带 noexcept
说明符);ref_mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()&
(带或不带 noexcept
说明符);vref_mem_fun<Class,Type,Key>
,如果 Key
的类型是 Type (Class::*)()volatile&
(带或不带 noexcept
说明符);global_fun<Value,Type,Key>
,如果 Key
的类型是 Type (*)(Value)
(带或不带 noexcept
说明符);key<Key0,...,Keyn>
解析为 composite_key<Value,KeyFromValue0,...,KeyFromValuen>
,其中KeyFromValuei
= key<Keyi>
对所有 i = 0,...,n
Value
= std::decay_t<Value0>
⊗ std::decay_t<Value1>
⊗ ··· ⊗ std::decay_t<Valuen>
,Valuei
对应于 KeyFromValuei
的相关 Class
或 Value
类型,而 T
⊗ Q
是 T
和 Q
之间的最不通用类型,定义为:如果 std::is_convertible_v<const T&,const Q&>
,则为 T
;如果 std::is_convertible_v<const Q&,const T&>
,则为 Q
;否则是未定义的。最后修订于 2020 年 4 月 19 日
© Copyright 2003-2020 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (请参阅随附文件 LICENSE_1_0.txt 或复制自 https://boost.ac.cn/LICENSE_1_0.txt)