Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2007-04-23 12:41:01


On Mon, April 23, 2007 18:27, Joaquín Mª López Muñoz wrote:
>
> Hello Ovanes, the issue of using a boost::tuple member as a key for
> a Boost.MultiIndex index has arisen in the past. Please read the
> following posts:
>
> http://lists.boost.org/boost-users/2005/12/16087.php
> http://lists.boost.org/boost-users/2005/12/16088.php
>
> Do they address your problem? Best regards,
>
> Joaquín M López Muñoz
> Telefónica, Investigación y Desarrollo
>

Thanks for the quick answer. If I correctly understand your answer, I will need either to use a
custom key extractor, but then I can't make lookup by key like int or string, since I am forced to
pass the whole tuple instance where the key is extracted. Is it true? Other solution would be to
avoid using tuples...

One more question, which might be offtopic. In my other scenario I use boost::hash to hash for
string member of a pair, but the find fails if I pass a string const& and works if I pass const
char*.

Here an example:

typedef std::pair<std::string, some_type const*> key_value_pair;

struct hash {}; //tag used to retrieve values

typedef mi::multi_index_container
<
        key_value_pair
, mi::indexed_by
        <
                mi::hashed_unique<mi::tag<hash>, BOOST_MULTI_INDEX_MEMBER(key_value_pair, std::string, first)>
>
> types_map;

This would fail:

inline some_type_ptr create_type(std::string const& name)const
{
     types_map::index<hash>::type::const_iterator i =types_.get<hash>().find(name);
     //...
}

But this works:

inline some_type_ptr create_type(std::string const& name)const
{
     types_map::index<hash>::type::const_iterator i =types_.get<hash>().find(name.c_str);
                                                                        ^^^^^^^^^^^^^^^^^
     //...
}

Many thanks and

With Kind Regards,

Ovanes Markarian


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