Boost logo

Boost :

From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2007-05-23 04:31:18

On 5/22/07, "JOAQUIN LOPEZ MU?Z" <joaquin_at_[hidden]> wrote:
> De: Péter Szilágyi <peterke_at_[hidden]>
> > I don't really want to add additional libraries, that aren't
> > needed. I'd
> > rather solve it with the already available tools.
> Boost.MultiIndex provides hashed indices, so you can
> emulate an unordered_set with a single-index
> multi_index_container.
> [snip]
> An emulation of an unordered map is a little more tricky
> and the result won't be TR1-compatible, but might be close
> enough for your needs

You can use Boost.Bimap.

    #include <boost/bimap/bimap.hpp>
    #include <boost/bimap/unordered_set_of.hpp>
    #include <boost/bimap/unconstrained_set_of.hpp>

    using boost::bimaps;

    typedef bimap<
        unordered_set_of<std::string>, unconstrained_set_of<int>
> bm_type;
    typedef bm_type::left_map map_type;

    bm_type bm;
    map_type & m = bm.left;

    // Use map as a std::unordered_map

    m["one"] = 1;
    m["two"] = 2;
    assert( m.find("one") != m.end() );
    m.insert( map_type::value_type("three",3) );
    assert( m.size() == 3 );

If you need unordered_multimap use unordered_multiset_of.

You can read more about Boost.Bimap here:

Best regards

Boost list run by bdawes at, gregod at, cpdaniel at, john at