Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] mutable transform
From: David Sankel (camior_at_[hidden])
Date: 2009-05-13 12:45:19


Answering my own question:

The separation of concerns can still be ensured in this case, but
using a form of nested bind, aka function composition.

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

Bind fortunately allows for the creation of hetero-argument-typed
function objects when the right-most function object in the functional
composition is also hetero-argument-typed. (this is a dense sentence,
but it is precise in its meaning).

Keep up your experimentation with this powerful library! The rewards
are truly worth it. ;-)

David

On Thu, May 7, 2009 at 10:21 AM, David Sankel <camior_at_[hidden]> wrote:
>
> 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

--
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