Boost C++ Libraries: Ticket #9840: phoenix V3 and stl container non const methods https://svn.boost.org/trac10/ticket/9840 <p> I'm using boost 1.53 (boost-devel-1.53.0-6.fc19.i686). I think I found a bug with phoenix and stl methods. It looks like boost assumes that all methods are const which is not true (eg vector::reserve). </p> <p> I tried to change: </p> <pre class="wiki">#define BOOST_PHOENIX_ADAPT_CALLABLE(NAME, FUNC, N) \ template &lt;BOOST_PHOENIX_typename_A(N)&gt; \ inline \ typename \ boost::phoenix::detail::expression::function_eval&lt; \ FUNC \ , BOOST_PHOENIX_A(N)&gt;::type const \ NAME(BOOST_PHOENIX_A_const_ref_a(N)) \ { \ return boost::phoenix::detail::expression:: \ function_eval&lt;FUNC, BOOST_PHOENIX_A(N)&gt;:: \ make(FUNC(), BOOST_PHOENIX_a(N)); \ } \ </pre><p> into </p> <pre class="wiki">#define BOOST_PHOENIX_ADAPT_CALLABLE(NAME, FUNC, N) \ template &lt;BOOST_PHOENIX_typename_A(N)&gt; \ inline \ typename \ boost::phoenix::detail::expression::function_eval&lt; \ FUNC \ , BOOST_PHOENIX_A(N)&gt;::type const \ NAME(BOOST_PHOENIX_A_ref_a(N)) \ { \ return boost::phoenix::detail::expression:: \ function_eval&lt;FUNC, BOOST_PHOENIX_A(N)&gt;:: \ make(FUNC(), BOOST_PHOENIX_a(N)); \ } \ </pre><p> but that's not enough. That part of the problem remains in git. But that is not sufficient, some other method in the chain imposes constness. </p> <p> phoenix should not try to impose constness IMHO, the chain of instantiations should just pass the orginal type... </p> <p> Here is a (not totally simplified as it uses spirit) example to reproduce the problem: </p> <pre class="wiki">#include &lt;boost/spirit/include/qi.hpp&gt; #include &lt;boost/spirit/include/phoenix.hpp&gt; #include &lt;boost/phoenix/stl.hpp&gt; #include &lt;boost/spirit/include/qi_uint.hpp&gt; #include &lt;boost/phoenix/phoenix.hpp&gt; std::vector&lt;unsigned&gt; L; int main() { using namespace boost::spirit::qi; using namespace boost::phoenix; using boost::phoenix::arg_names::_1; const std::string str("3 1 2 3"); std::string::const_iterator first = str.begin(); parse(first,str.end(), uint_[reserve(L,_1)] &gt;&gt; repeat(capacity(L))[ uint_ ]); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9840 Trac 1.4.3 Theodore.Papadopoulo@… Sun, 06 Apr 2014 08:11:57 GMT attachment set https://svn.boost.org/trac10/ticket/9840 https://svn.boost.org/trac10/ticket/9840 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.C</span> </li> </ul> <p> File to reproduce the problem </p> Ticket Theodore.Papadopoulo@… Sun, 06 Apr 2014 08:14:43 GMT <link>https://svn.boost.org/trac10/ticket/9840#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9840#comment:1</guid> <description> <p> I forgot, this is to be compiled with: </p> <p> g++ -DBOOST_SPIRIT_USE_PHOENIX_V3 test.C </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sun, 06 Apr 2014 11:44:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9840#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9840#comment:2</guid> <description> <p> Please post a test cpp file that does not use Spirit. A phoenix-only test will make it clear that this is a phoenix bug, if it is indeed a bug. </p> </description> <category>Ticket</category> </item> <item> <author>Theodore Papadopoulo <Theodore.Papadopoulo@…></author> <pubDate>Mon, 07 Apr 2014 11:06:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9840#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9840#comment:3</guid> <description> <p> I cannot, I tried some obvious code, but I do not know phoenix much. Can you requalify it as a spirit bug ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 07 Apr 2014 13:42:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9840#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9840#comment:4</guid> <description> <p> Wait, I see the problem and it's not a phoenix bug nor a spirit bug. It's a usage bug. </p> <p> 1) L is captured by value, by default. Use ref if you want to capture by reference 2) Use boost::spirit::qi::_1 instead of boost::phoenix::arg_names::_1 </p> <p> Here's the working code: </p> <pre class="wiki"> #include &lt;boost/spirit/include/qi.hpp&gt; #include &lt;boost/spirit/include/phoenix.hpp&gt; #include &lt;boost/phoenix/stl.hpp&gt; #include &lt;boost/spirit/include/qi_uint.hpp&gt; #include &lt;boost/phoenix/phoenix.hpp&gt; std::vector&lt;unsigned&gt; L; int main() { using namespace boost::spirit::qi; using namespace boost::phoenix; using boost::spirit::qi::_1; namespace phx = boost::phoenix; const std::string str("3 1 2 3"); std::string::const_iterator first = str.begin(); parse(first,str.end(), uint_[reserve(phx::ref(L),_1)] &gt;&gt; repeat(capacity(phx::cref(L)))[ uint_ ]); } </pre><p> I'll leave it up to you to close this ticket. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Wed, 09 Apr 2014 01:30:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9840#comment:5 https://svn.boost.org/trac10/ticket/9840#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> I'm closing this one. Feel free to re-open if you have objections. </p> Ticket