Joaquin, Am Donnerstag, 4. Dezember 2008 21:18:36 schrieb Joaquin M Lopez Munoz:
HostSetOrderedIndex &oi = s.get<0>(); oi.insert(p1); oi.insert(p2);
oi.erase(p1); // booom }
This can't possibly compile: erase() can accept either an iterator or a key, and p1 is neither. You can write:
oi.erase(p1->ip());
D'ough! In the very minute before I read your mail I figured that out myself. Thanks a lot for confirming that. Now it seems so obvious. However, it does require the user to know about that giveip() magic and what I'm doing here, which is slightly different from the expected set semantics, but i'll hide it away anyway.
and everything compiles and works just fine. Your key for HostSetOrderedIndex is std::string, which is exactly what you want AFAICS.
...well, actually it's asio::ip::address but I get your point.
Yes, this is what you currently have, HostPtrs are indexed by IP. And the key extractor works, it's only the confusion about erase that I think is misleading you.
Indeed it was. Big time. Could one make this a little easier to code? I'll write some erase overload template for that.
In this variation the key is HostPtr, which are sorted by their IPs. Noy you could legitimately use oi.erase(p1), for instance, though the former version is probably better because it allows you to lookup passing only a string instead of a whole HostPtr, which is more expensive to create.
Is that so? I've had the impression that version was broken because it sorted by pointer value and...
This is because hsri.sort() does the sorting based on std::less<HostPtr>, which is not what you want. Write this instead:
hsri.sort(lthost());
...that was default and took the functor you give in at the declaration. Anyway, now I think you're just right and I can finally have peace of mind on that one.
to explicitly specify that you want your elements sorted according to lthost. Note that the fact that HostSetOrderedIndex uses lthost does not affect in any manner the way HostSetRandomIndex operates.
Ahhh, that is what you meant. I did specify lthost for the ordered index, but never for the random index. That's why the sort() went wrong. All right. It isn't possible to specify lthost for these operations in the RandomIndex parameters, is it? Anyway, just curious. One working version is just fine, especially since it's the more efficient one. Great lib, that MultiIndex! I just love it, and well documented too. Thanks for your help. Stephan