Boost logo

Boost Users :

From: Joel de Guzman (joel_at_[hidden])
Date: 2008-07-07 23:07:20


Istvan Buki wrote:
> Dear boost experts,
>
> I have difficulties using the fusion join algorithm result.
> Here is a small sample demonstrating the problem.
>
> namespace fields
> {
> struct one ;
> struct two ;
> }
>
>
> typedef fusion::map <
> fusion::pair< fields::one, std::string >,
> fusion::pair< fields::two, std::string >
> > rec_t ;
>
>
> int
> main()
> {
> rec_t r1( std::string( "1" ), std::string( "2" ) ) ;
> rec_t r2( std::string( "10" ), std::string( "20" ) ) ;
>
> typedef fusion::result_of::join< const rec_t, const rec_t >::type
> res_type ;
> res_type res = fusion::join( r1, r2 ) ;
>
> // Compile error!
> fusion::at_key< fields::two >( res ) = std::string( "200" ) ;
>
> std::cout << res << std::endl ;
> }
>
> I can not modify the map fields because they are const.
> I tried changing the result type from
>
> typedef fusion::result_of::join< const rec_t, const rec_t >::type
> res_type ;
> to
> typedef fusion::result_of::join< rec_t, rec_t >::type res_type ;
>
> but that doesn't work neither.
>
> Can somebody explain how to assign the result of a join to a variable
> that I can modify later
> using functions like at_key, erase_key,... ?

When you join a sequence, A, and another sequence, B, the result is
a joint_sequence -- a view. IOTW, when you join a map and another
map, the result is not a map. What you can do is to convert the
view to a map using as_map(res).

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net