Boost logo

Boost Users :

Subject: [Boost-users] [fusion] mutable transform
From: David Sankel (camior_at_[hidden])
Date: 2009-05-07 10:21:10


Hello,

I'm using boost fusion to do some interesting robotics work. This has
come up on the list before, but I'd like to point out my scenario
where a mutable transform function would be useful.

I'm writing a generic interface generator for various datatypes. For a
given instance of the type, the interface generator return a widget
that can modify the instance.

I'd like my implementation for map types to look like this:

    //...
    for_each( transform( mapInstance
                       , toWidget()
                       )
            , bind( Layout::addWidget, layout, _1 )
            );
    //...

It has a very nice separation of concerns: 1) the "transform toWidget"
function, and 2) the "for_each addWidget" which acts much like a fold.

However, my toWidget function requires a non-const reference so this
doesn't work without a hacky cast to remove the const.

Hackery aside, the only way I know how do to this is using a for_each
who's function argument explicity does both the conversion to a widget
(with toWidget()) and the folding to the layout. Those two concepts
seem separate to me.

Maybe there's a better way or maybe I'm not understanding the
drawbacks of exposing a mutable transpose function.

Thanks,

David

--
David Sankel
Sankel Software
www.sankelsoftware.com

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