|
Boost : |
From: Andy Glew (glew_at_[hidden])
Date: 1999-10-08 01:15:02
Oh, I forgot to mention: in my own work,
my relations are usually not between scalar keys,
but are between objects, as in
multi_map<Producer*,Consumer*> forward_map;
map<Consumer*,Producer*> reverse_map;
You can grossly encapsulate this, if you make the fairly
universal but nonetheless ugly assumption that
map<void*,void*>
is interconvertible with
map<Consumer*,Producer*>
with suitable casts
thereby avoiding the mutual recursion in the definition.
===
Also, I wasted a lot of time trying to make
Left.rightptr = &Right
automatically update Right.leftptr, and vice versa.
In terms of your problem, that would be like saying
map2way.forward_map[key] = value
automatically adding pair<ValueType,KeyType>(value,key)
to the reverse_map.
I eventually figured out how to do it, but it is kind of gross,
requiring what amounts to subtracting the offset of a member
from the member's address, to arrive at a pointer to the object
containing the member. Works everywhere I have tried it,
but I don't think that it is guaranteed to be portable.
I think that it is better to define a linking operation
reln_1_to_N::link( KeyType k, ValueType v )
and just use the array [ ] notation for lookup.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk