Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Controlling set types

As has already been said, in STL maps, you can only control the constraints from one of the collections, namely the one that you are viewing.

extended.mapping.framework

In Boost.Bimap, you can control both and it is as easy as using the STL. The idea is to use the same constraint names that are used in the standard. If you don't specify the collection type, Boost.Bimap assumes that the collection is a set. The instantiation of a bimap with custom set types looks like this:

typedef bimap< SetType_of<A>, SetType_of<B> > bm_type;

The following is the list of all supported set types.

Set of Key Types
name Features map view type
set_of  ordered, unique map 
multiset_of  ordered multimap 
unordered_set_of  hashed, unique unordered_map 
unordered_multiset_of hashed unordered_multimap 
list_of  sequenced list_map 
vector_of  random access vector_map 
unconstrained_set_of  unconstrained can not be viewed 

list_of and vector_of map views are not associated with any existing STL associative containers. They are two examples of unsorted associative containers. unconstrained_set_of allow the user to ignore a view. This will be explained later.

bimap.structures

The selection of the set type affects the possible operations that you can perform with each side of the bimap and the time it takes to do each. If we have:

typedef bimap< SetType_of<A>, SetType_of<B> > bm_type;
bm_type bm;

The following now describes the resulting map views of the bidirectional map.

Configuration parameters

Each set type template has different parameters to control its behaviour. For example, in set_of specification, you can pass a Functor type that compares two types. All of these parameters are exactly the same as those of the standard library container, except for the allocator type. You will learn later how to change the allocator for a bimap.

The following table lists the meanings of each set type's parameters.

name Additional Parameters
set_of<T,KeyComp>
multiset_of<T,KeyComp> 
KeyComp is a Functor that compares two types using a less-than operator. By default, this is std::less<T>.
unordered_set_of<T,HashFunctor,EqualKey>
unordered_multiset_of<T,HashFunctor,EqualKey>
HashFunctor converts a T object into an integer value. By default it is boost::hash<T>.
EqualKey is a Functor that tests two types for equality. By default, the equality operator is std::equal_to<T>.
list_of<T>  No additional parameters.
vector_of<T>  No additional parameters.
unconstrained_set_of<T>  No additional parameters.
Copyright © 2006 Matias Capeletto

PrevUpHomeNext