|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2007-06-01 19:31:24
Matias Capeletto wrote:
>
> I want to use this with my bimaps (I will add a section Bimap and
> Boost.Xpressive to my Bimap and Boost.? docs) but I do not know the
> correct approach.
> Because bimaps have other constraints than maps, I can not provide
> operator[] for insertion. I have to use the usual insert.
>
> This works as you said: (operator[] is provided for this bimap
> because list_of collection type does not impose additional
> constraints)
>
> ----------------------------------------------------------------------------
> typedef bimap< std::string, list_of< int > > bm_type;
> bm_type bm;
>
> std::string str("aaa=>1 bbb=>23 ccc=>456");
> sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )
> [ xp::ref(bm.left)[ s1 ] = as<int>(s2) ];
> ----------------------------------------------------------------------------
>
> But when operator[] is not present I have tried to use insert
> but failed.
> Being able to parse a file is a nice addition to bimap docs.
> I know I have to wait to your docs but I want to know now :)
> Can you help me?
Sure. What is the signature of bimap::insert? In
xpressive/regex_action.hpp, there is a lazy insert function object that
can be used to insert stuff into sequences, strings and associative
containers. For instance, my example could have been written as:
sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )
[ insert(ref(result), make_pair(s1, as<int>(s2))) ];
which is also equivalent, via some Proto magic, to:
sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )
[ ref(result)->*insert(make_pair(s1, as<int>(s2))) ];
But be sure to sync up. I just had to add xpressive::make_pair. :-)
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk