Compound key searches do not go through any two-step process as you describe. composite_key -induced orderings are normal orders, the only feature is that it depends on two or more element keys, not one.
Perhaps an example will explain. Consider this use of composite_key :
struct element { int x,y,z; }; typedef multi_index_container< element, indexed_by< ordered_unique< composite_key< element, member<element,int,&element::x>, member<element,int,&element::y>, member<element,int,&element::z> > > > > multi_t;
The resulting container is in a sense equivalent to this:
struct element_cmp { bool operator()(const element& v1, const element& v2)const { if(v1.x<v2.x)return true; if(v2.x<v1.x)return false; if(v1.y<v2.y)return true; if(v2.y<v1.y)return false; return v1.z<v2.z; } }; typedef std::set<element,element_cmp> set_t;
composite_key automatically generates the equivalent code in element_cmp::operator() and additionally allows you to search only the first n keys, but the basic data structure does not change with respect to the case using std::set .
source share