Re: [Boost-users] [MultiIndex] more on key extractor issues

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

John M. Dlugosz
Have you taken a look at the table in:
http://www.boost.org/libs/multi_index/doc/tutorial/ key_extraction.html#advanced_key_extractors
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.
Sorry to hear that: the section's declared intent is to show how to use member and fun extractors in the various constness scenarios with and without pointers involved. Admittedly the subject gets rapidly complicated, hence the inclusion of this very section in the docs.
"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?
Consider these two scenarios
// scenario #1
struct T{int f();};
multi_index_container
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_containers 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?
The key extractor are general-purpose utilities, what the table shows is that you can't use them with multi_index_container's in some scenarios (but you can in others)
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.
The differences in usage stem from the fact that constness, when referring
to a member or member function can apply to
1. access restrictions
2. type returned
Consider the following
struct T
{
const X f();
X g()const;
};
In order to index by f, one has to use
mem_fun
participants (2)
-
Joaquin M Lopez Munoz
-
John M. Dlugosz