From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2007-02-25 23:18:07
I think we must discuss this issue together so we can settled it down.
Lets analyze the rationale step by step.
(1) Interface for the bidirectional mapping. That interface have to be
compatible with existing code that work with standard maps. The best
way IMHO to achieve this is that you can view the container from the
two sides and see something compatible with std::map<X,Y> for the left
one and with std::map<Y,X> for the right one.
(2) This force us to use first/second notation for the left view
(first is the left element and second the right one) and for the right
view (where the names are inverted, first is the right element and
second is the left one)
If you have code like:
template< class Pair >
void operator()( const Pair& p )
std::cout << p.first << "-->" << p.second << std::endl;
template< class Map >
void print( const Map & m )
std::for_each( m.begin(), m.end(), PrintPair< Map::value_type >() );
typedef bimap<int,std::string> bm_type;
bm.insert( bm_type::value_type(1,"one") );
bm.insert( bm_type::value_type(2,"two") );
It will work with both sides views
print( bm.left );
// 1 --> one
// 2 --> two
print( bm.right );
// one --> 1
// two --> 2
(3) (from other thread) For bm (the above view) we have some options:
a) bm can be left without any special function and so force the user
to write .left or .right to refer to it.
b) bm can be the same as bm.left. This IMHO introduce an asymmetry to
the interface. The left view became the more important than the right
c) bm can be used for something new. Give the user a new view of the
mapping: a set of relations. This design is symmetric. It forces the
user to write .left to refer to the std::map<X,Y> view but this is a
good thing, because is documented in the code what view is being used.
This option is more elegant and powerful that the other ones.
Because it is a new view we can use the symmetric left/right notation for
it members so the design is complete. If we use first and second, the
above view could be confused with the left view.
Jeff has proposed to go with (a)
In the current framework this is achieve using:
typedef bimap<A,B,unconstrained_set_of_relation> bm_type;
The library use (c) because it is very useful to be able to insert the
elements or ask for the size, etc directly. And because it allows us
to extend the framework by selecting different set of relations.
So first/second are used in the side views and left/right in the above view.
What do you think about this?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk