Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4582 closed Bugs (fixed)

fold() doesn't work with function objects that don't support perfect forwarding

Reported by: anonymous Owned by: Christopher Schmidt
Milestone: To Be Determined Component: fusion
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

the unrolled specializations of fold() are implemented as

f(f(f(state,a),b),c)

if f is a function object that doesn't support perfect forwarding, but only accepts "T &" arguments, this doesn't work.

this is e.g. the case for all phoenix::bind() results:

int f(int,int,int){ return 0; }

int main(){
    fusion::vector<int,int> vec;
    fusion::fold(vec,0,phoenix::bind(&f,_1,_2,3)); //error
}

AFAIK a bind() cannot support perfect forwarding and at the same time support the result_of protocol, not even for up to 2 arguments as Boost.Bind does.

attached is a patch that changes that.

Change History (8)

comment:1 by anonymous, 12 years ago

trac thinks my patch is spam. here it is on codepad: http://boost.codepad.org/nXmMG0O2

comment:2 by Christopher Schmidt, 12 years ago

Owner: changed from Joel de Guzman to Christopher Schmidt
Status: newassigned

That makes sense. Is there any reason for the state instances to be 'const'?

comment:3 by anonymous, 12 years ago

no particular reason, other than that it is a variable that is never mutated. is there any reason for them not to be const?

comment:4 by Christopher Schmidt, 12 years ago

The functor should be able to modifiy the state. I think moving the passed state to the new one is a quite common usecase.

I will commit your patch (with non-const states) asap.

comment:5 by anonymous, 12 years ago

that makes sense, but there is no fusion::fold documented that takes a non-const reference to the initial state. so passing a functor to fold() that requires a non-const reference to the state in order to move it would fail. the initial call to f passes a const state.

comment:6 by Christopher Schmidt, 12 years ago

Right, I was thinking about the c++11-port (which perfect-forwards the state). Thanks for the remark!

comment:7 by Christopher Schmidt, 12 years ago

Resolution: fixed
Status: assignedclosed

Fixed in [64947]

comment:8 by anonymous, 12 years ago

thanks!

Note: See TracTickets for help on using tickets.