Reputation: 379
I am applying example 6 of boost multi_index examples. https://www.boost.org/doc/libs/1_71_0/libs/multi_index/doc/examples.html#example6
I am still learning the syntax of key extraction.i find that member
key extractor require for its third argument a pointer to class
member of type type
where class is first arg and type is second arg .
template<class Class,typename Type,Type Class::*PtrToMember>
struct member;
But in example 6 the author uses 3rd arg which is not pointer .....
key_from_key<
member<car_manufacturer,
const std::string,
&car_manufacturer::name>,
member<car_model,
const car_manufacturer *,
car_model::manufacturer> >
this should be &
to make pointer which points to the member of class car_model
of type const car_manufacturer *
so giving us pointer to pointer
.....but he just use the member identifiercar_model::manufacturer
which is only pointer to member.
So why did the author omits the &
from third argument??
if any more code required i will put it.
Upvotes: 0
Views: 115
Reputation: 5658
Congratulations, you found an error in Boost.MultiIndex docs :-)
It should be &car_model::manufacturer
rather than car_model::manufacturer
, as you correctly point out. What's more, car_model::manufacturer
is not even legal C++, as, if anything, it would declare a reference to a member, which does not exist in the language.
Additionally, the docs say:
struct car_model
{
std::string model;
car_manufacturer* manufacturer;
int price;
};
where it should be (as correctly written in the actual code):
struct car_model
{
std::string model;
const car_manufacturer* manufacturer;
int price;
};
Otherwise, member<car_model,const car_manufacturer *,&car_model::manufacturer>
wouldn't match the type of the manufacturer
member.
I'll fix all of this in the docs. Thanks for spotting the mess.
Upvotes: 2