Boost C++ Libraries: Ticket #5626: Compilation error when using boost::phoenix with range adaptors https://svn.boost.org/trac10/ticket/5626 <p> The following piece of code fails to compile with gcc-4.5: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/range.hpp&gt; #include &lt;boost/range/irange.hpp&gt; #include &lt;boost/range/adaptors.hpp&gt; #include &lt;boost/phoenix.hpp&gt; using namespace boost::phoenix::arg_names; using namespace boost::adaptors; int main() { std::cout &lt;&lt; *boost::begin(boost::irange(0,5) | transformed( arg1 +1)); } </pre><p> The error is: </p> <pre class="wiki">In file included from /usr/local/mkt-dev/src/boost_1_47_0_rc/boost/range/adaptor/transformed.hpp:16:0, from /usr/local/mkt-dev/src/boost_1_47_0_rc/boost/range/adaptor/map.hpp:14, from /usr/local/mkt-dev/src/boost_1_47_0_rc/boost/range/adaptors.hpp:20, from test2.cpp:4: /usr/local/mkt-dev/src/boost_1_47_0_rc/boost/iterator/transform_iterator.hpp: In member function ‘typename boost::detail::transform_iterator_base&lt;UnaryFunc, Iterator, Reference, Value&gt;::type::reference boost::transform_iterator&lt;UnaryFunction, Iterator, Reference, Value&gt;::dereference() const [with UnaryFunc = boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0l&gt; &gt;, Iterator = boost::range_detail::integer_iterator&lt;int&gt;, Reference = boost::use_default, Value = boost::use_default, typename boost::detail::transform_iterator_base&lt;UnaryFunc, Iterator, Reference, Value&gt;::type::reference = int&amp;]’: /usr/local/mkt-dev/src/boost_1_47_0_rc/boost/iterator/iterator_facade.hpp:517:32: instantiated from ‘static typename Facade::reference boost::iterator_core_access::dereference(const Facade&amp;) [with Facade = boost::transform_iterator&lt;boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0l&gt; &gt;, boost::range_detail::integer_iterator&lt;int&gt;, boost::use_default, boost::use_default&gt;, typename Facade::reference = int&amp;]’ /usr/local/mkt-dev/src/boost_1_47_0_rc/boost/iterator/iterator_facade.hpp:643:67: instantiated from ‘reference boost::iterator_facade&lt;I, V, TC, R, D&gt;::operator*() const [with Derived = boost::transform_iterator&lt;boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0l&gt; &gt;, boost::range_detail::integer_iterator&lt;int&gt;, boost::use_default, boost::use_default&gt;, Value = int, CategoryOrTraversal = boost::detail::iterator_category_with_traversal&lt;std::input_iterator_tag, boost::random_access_traversal_tag&gt;, Reference = int&amp;, Difference = long int, reference = int&amp;]’ test2.cpp:13:70: instantiated from here /usr/local/mkt-dev/src/boost_1_47_0_rc/boost/iterator/transform_iterator.hpp:121:31: error: invalid initialization of reference of type ‘int&amp;’ from expression of type ‘const int’ </pre><p> It seems that result_of&lt;arg1(int)&gt; returns int&amp; instead of int. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5626 Trac 1.4.3 Nicolas Savoire <nicos@…> Tue, 21 Jun 2011 15:35:55 GMT <link>https://svn.boost.org/trac10/ticket/5626#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5626#comment:1</guid> <description> <p> Ooops, I made a mistake, the failing example is: </p> <pre class="wiki"> #include &lt;iostream&gt; #include &lt;boost/range.hpp&gt; #include &lt;boost/range/irange.hpp&gt; #include &lt;boost/range/adaptors.hpp&gt; #include &lt;boost/phoenix.hpp&gt; using namespace boost::phoenix::arg_names; using namespace boost::adaptors; int main() { std::cout &lt;&lt; *boost::begin(boost::irange(0,5) | transformed( arg1 )); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Thomas Heller</dc:creator> <pubDate>Wed, 29 Jun 2011 14:21:19 GMT</pubDate> <title>status, version changed; resolution set https://svn.boost.org/trac10/ticket/5626#comment:2 https://svn.boost.org/trac10/ticket/5626#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost Release Branch</span> → <span class="trac-field-new">Boost Development Trunk</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <blockquote class="citation"> <p> It seems that result_of&lt;arg1(int)&gt; returns int&amp; instead of int. </p> </blockquote> <p> Good observation. This shouldn't be the case. The right return type is "int const &amp;" in that case. I commit the necessary fix to trunk. And will ask the release managers to merge to release so the release won't suffer this defect. However, it is quite late in the release process, so chances are that it won't make it. </p> <p> As a small workaround, I suggest the following: </p> <pre class="wiki">boost::irange(0,5) | transformed( val( arg1 ) ) </pre><p> Thanks for your report. </p> Ticket Thomas Heller Wed, 29 Jun 2011 16:14:43 GMT milestone changed https://svn.boost.org/trac10/ticket/5626#comment:3 https://svn.boost.org/trac10/ticket/5626#comment:3 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.47.0</span> </li> </ul> Ticket Nicolas Savoire <nicos@…> Wed, 29 Jun 2011 16:23:20 GMT <link>https://svn.boost.org/trac10/ticket/5626#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5626#comment:4</guid> <description> <p> Thanks for the quick fix ! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Thomas Heller</dc:creator> <pubDate>Thu, 30 Jun 2011 08:10:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5626#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5626#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/5626#comment:4" title="Comment 4">Nicolas Savoire &lt;nicos@…&gt;</a>: </p> <blockquote class="citation"> <p> Thanks for the quick fix ! </p> </blockquote> <p> No problem. The tests on the release branch look good. The fix will be part of 1.47.0 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Thomas Heller</dc:creator> <pubDate>Wed, 13 Jul 2011 07:55:07 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/5626#comment:6 https://svn.boost.org/trac10/ticket/5626#comment:6 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost Development Trunk</span> → <span class="trac-field-new">Boost 1.47.0</span> </li> </ul> Ticket