Boost logo

Boost Users :

Subject: Re: [Boost-users] [MultiIndex] more on key extractor issues
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2013-01-20 05:08:39


> Have you taken a look at the table in:
>
> http://www.boost.org/libs/multi_index/doc/tutorial/
> key_extraction.html#advanced_key_extractors
>
> Regardless of whether the indexed-by member is const or not, when using
> pointers to const elements the proper way of declaring the extractors is:
>
>
> member<
> ItemBase,
> const unsigned long,
> &ItemBase::some_member
> >
>
> member<
> ItemBase,
> const S2,
> &ItemBase::another_member
> >
>
> This should clear problems away both in VS and Clang (please report
> otherwise.)
>
> Joaqu?n M L?pez Mu?oz
> Telef?nica Digital
>
>

I read that part in detail (including the typo, T:gg instead of T::gg), going over all the
MI docs again after my postings. I agree this seems to address that use-case, but I
really don't understand the table and section, and certainly had no clue what it was
getting at when I read it without this issue specifically in mind.

"The column "applicable to |const| elements?" states whether the corresponding key
extractor can be used when passed constant elements (this relates to the elements
specified in the first column, not the referenced |T| objects)." What does that mean?
I was actually looking at this in regards to figuring out what a non-const member function
extractor was good for.
"this also implies that |multi_index_container|s of elements of |T| cannot be sorted by
|T::g| or |T::gg|," if you are not using it to sort by, what is the point of having the
key extractor?

Anyway, I found that it works correctly on both compilers if the middle argument (the key
type) is declared const for member and not for const_mem_fun. I suppose that is due to
differences in the metaprogramming, but really they should be treated the same. Const on
the first parameter, T, doesn't seem to matter if it's declared const or not.

---John



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net