Boost C++ Libraries: Ticket #8775: fusion transform and fold not respecting const-ness of the sequence https://svn.boost.org/trac10/ticket/8775 <p> The following does not compile: </p> <pre class="wiki">#include &lt;boost/fusion/include/vector.hpp&gt; #include &lt;boost/fusion/include/transform.hpp&gt; #include &lt;boost/fusion/include/fold.hpp&gt; #include &lt;boost/fusion/include/copy.hpp&gt; namespace fusion = boost::fusion; struct F { typedef int result_type; int operator()(int state, int &amp; val) const { return state; } }; struct G { typedef int result_type; int operator()(int &amp; val) const { return val; } }; int main() { fusion::vector&lt;int, int&gt; v(1,2); fusion::vector&lt;int, int&gt; v2; // fold does not respect constness fusion::fold(v, 42, F()); // transform does not respect constness fusion::copy(fusion::transform(v, G()), v2); } </pre><p> In my opinion, it should. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8775 Trac 1.4.3 Eric Niebler Wed, 03 Jul 2013 21:15:27 GMT <link>https://svn.boost.org/trac10/ticket/8775#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8775#comment:1</guid> <description> <p> I should note that it actually does compile with msvc, but that's a compiler bug. With gcc and clang, it fails. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Jul 2013 23:49:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8775#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8775#comment:2</guid> <description> <p> I'm not sure I understand. Both sequences are non-const above. Also, the call to fold compiles on gcc 4.7.2. Should it not? I'll take a look at the second as soon as I understand some more. What am I missing? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Fri, 05 Jul 2013 23:53:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8775#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8775#comment:3</guid> <description> <p> woops, that anonymous is Joel. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Eric Niebler</dc:creator> <pubDate>Sun, 07 Jul 2013 21:44:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8775#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8775#comment:4</guid> <description> <p> Right, the sequences are both non-const lvalues, so the elements passed to <code>F</code> and <code>G</code> should also be non-const lvalues. But they're not. They're const lvalues, which means they can't bind to the non-const references. </p> <p> You should double-check that gcc compiles it successfully. I just tested locally with gcc 4.7.0 and gcc 4.8.1, and compilation fails for both, as well as for clang-trunk. </p> <p> A quick inspection of the code shows why the <code>transform</code> call fails to compile. There is no overload of <code>transform</code> that takes a non-const sequence. <code>fold</code> is tricker. You would need to dig to find out what's going on there. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Eric Niebler</dc:creator> <pubDate>Sun, 07 Jul 2013 21:48:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8775#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8775#comment:5</guid> <description> <p> Oh, you're right about <code>fold</code>. It works on gcc, but fails on clang 3.3. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sun, 07 Jul 2013 23:44:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8775#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8775#comment:6</guid> <description> <p> Originally, Fusion algorithms are pure FP style const non mutating. Why? because they are held by reference and when you concat/build compound algos, my thinking was that it would be weird to have some of the algos mutate the sequence. Slowly, non const versions crept in. People kept on asking. I guess it's time to break free from the design and have all fusion algos take const and non-const sequences. </p> </description> <category>Ticket</category> </item> </channel> </rss>