Boost C++ Libraries: Ticket #4582: fold() doesn't work with function objects that don't support perfect forwarding https://svn.boost.org/trac10/ticket/4582 <p> the unrolled specializations of fold() are implemented as </p> <pre class="wiki">f(f(f(state,a),b),c) </pre><p> if f is a function object that doesn't support perfect forwarding, but only accepts "T &amp;" arguments, this doesn't work. </p> <p> this is e.g. the case for all phoenix::bind() results: </p> <pre class="wiki">int f(int,int,int){ return 0; } int main(){ fusion::vector&lt;int,int&gt; vec; fusion::fold(vec,0,phoenix::bind(&amp;f,_1,_2,3)); //error } </pre><p> 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. </p> <p> attached is a patch that changes that. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4582 Trac 1.4.3 anonymous Sat, 21 Aug 2010 18:59:38 GMT <link>https://svn.boost.org/trac10/ticket/4582#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4582#comment:1</guid> <description> <p> trac thinks my patch is spam. here it is on codepad: <a class="ext-link" href="http://boost.codepad.org/nXmMG0O2"><span class="icon">​</span>http://boost.codepad.org/nXmMG0O2</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Sun, 22 Aug 2010 11:48:15 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/4582#comment:2 https://svn.boost.org/trac10/ticket/4582#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Joel de Guzman</span> to <span class="trac-author">Christopher Schmidt</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> That makes sense. Is there any reason for the state instances to be 'const'? </p> Ticket anonymous Sun, 22 Aug 2010 12:26:43 GMT <link>https://svn.boost.org/trac10/ticket/4582#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4582#comment:3</guid> <description> <p> no particular reason, other than that it is a variable that is never mutated. is there any reason for them not to be const? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Sun, 22 Aug 2010 12:32:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4582#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4582#comment:4</guid> <description> <p> The functor should be able to modifiy the state. I think moving the passed state to the new one is a quite common usecase. </p> <p> I will commit your patch (with non-const states) asap. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 22 Aug 2010 12:38:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4582#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4582#comment:5</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Sun, 22 Aug 2010 12:41:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4582#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4582#comment:6</guid> <description> <p> Right, I was thinking about the c++11-port (which perfect-forwards the state). Thanks for the remark! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Sun, 22 Aug 2010 13:19:00 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4582#comment:7 https://svn.boost.org/trac10/ticket/4582#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in <a class="changeset" href="https://svn.boost.org/trac10/changeset/64947" title="lvalue fold states. Fixes #4582">[64947]</a> </p> Ticket anonymous Sun, 22 Aug 2010 14:00:11 GMT <link>https://svn.boost.org/trac10/ticket/4582#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4582#comment:8</guid> <description> <p> thanks! </p> </description> <category>Ticket</category> </item> </channel> </rss>