Boost C++ Libraries: Ticket #8704: Using Phoenix lambdas on top of custom Proto expressions https://svn.boost.org/trac10/ticket/8704 <p> Some prehistory: </p> <p> I am working on VexCL (https :<em>github.com/ddemidov/vexcl) - a vector expression template library for OpenCL. I have recently added support for automatic generation of OpenCL kernels from generic functors (description of the feature: https :</em>github.com/ddemidov/vexcl#function-generator). </p> <p> In order to implement this, I pass the instances of vex::symbolic&lt;T&gt; class to the given functor. vex::symbolic&lt;T&gt; dumps to output stream any arithmetic operations it is being subjected to, and that's how I am able to construct the OpenCL kernel source. The symbolic&lt;T&gt; class is of course a Boost.Proto terminal. </p> <p> Now, it seems natural to use Boost.Phoenix to provide the generic functors for the function generator. And indeed it is possible with simple expressions (see https :<em>github.com/ddemidov/vexcl/blob/a95dfdd68/tests/generator.cpp#L124). However, if I try to bring cmath functions overloads from &lt;boost/phoenix/stl/cmath.hpp&gt; and use those (https :</em>github.com/ddemidov/vexcl/commit/b95da14e51), I get compilation errors. The reason apparently is that boost::phoenix_impl::&lt;function&gt;_impl assumes that result of &lt;function&gt;(expr) has the same type as expr itself. This of course is not true if expr is a Boost.Proto expression. </p> <p> Everything works as intended with the following patch: </p> <pre class="wiki">--- a/cmath.hpp +++ b/cmath.hpp @@ -25,11 +25,11 @@ namespace boost { struct result&lt;This(BOOST_PHOENIX_A(n))&gt; \ { \ typedef \ - typename proto::detail::uncvref&lt;A0&gt;::type \ + decltype( name(typename proto::detail::uncvref&lt;A0&gt;::type()) ) \ type; \ }; \ template&lt;BOOST_PHOENIX_typename_A(n)&gt; \ - A0 operator()(BOOST_PHOENIX_A_const_ref_a(n)) const { \ + auto operator()(BOOST_PHOENIX_A_const_ref_a(n)) const -&gt; decltype( name(BOOST_PHOENIX_a(n)) ) { \ using namespace std; \ return name(BOOST_PHOENIX_a(n)); \ } \ </pre><p> I understand this is unacceptable in its current form (because it uses c++11 features), but I could not come up with other solution (e.g. in terms of boost::result_of). </p> <p> Sorry for the broken links, Trac did not allow me to submit otherwise. Best regards, Denis </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8704 Trac 1.4.3 John Fletcher <J.P.Fletcher@…> Sun, 02 Feb 2014 17:34:22 GMT <link>https://svn.boost.org/trac10/ticket/8704#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8704#comment:1</guid> <description> <p> I am applying your patch like this: </p> <p> #ifdef BOOST_NO_CXX11_DECLTYPE &lt;old code&gt; #else &lt;your patch&gt; #endif </p> <p> Do you have a test for it? </p> </description> <category>Ticket</category> </item> <item> <author>John Fletcher <J.P.Fletcher@…></author> <pubDate>Sun, 02 Feb 2014 18:03:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8704#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8704#comment:2</guid> <description> <p> I have applied the patch and it is on test on <code>develop</code>. The test cmath applies to this. </p> <p> I had already applied <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6665" title="#6665: Bugs: not-unary phoenix stl cmath adapted functions not working (closed: fixed)">#6665</a> which corrected an error for functions with more than 1 argument. </p> </description> <category>Ticket</category> </item> <item> <author>ddemidov@…</author> <pubDate>Sun, 02 Feb 2014 18:26:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8704#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8704#comment:3</guid> <description> <p> Hello, </p> <p> Thank you very much for looking into this! </p> <p> The VexCL test for Phoenix cmath functions (github.com/ddemidov/vexcl/blob/b95da14e51387e955ba83fd470f8677f9044c004/tests/generator.cpp#L125-L142) compiles and runs fine against github.com/boostorg/phoenix/commit/1ffca907da5842e2ebbbcf7155288ed60ffb75d8. </p> <p> I do not know how to run native Boost.Phoenix tests though (in case this breaks anything). </p> <p> Again, thanks! </p> </description> <category>Ticket</category> </item> <item> <author>John Fletcher <J.P.Fletcher@…></author> <pubDate>Sun, 02 Feb 2014 18:37:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8704#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8704#comment:4</guid> <description> <p> Thank you for the feedback. I cannot test your bug directly, so it is very good to know your problem now works. All I can do is run the test cmath and see if it runs on different compilers, both C++03 and C++11. You can see that here: </p> <p> <a href="http://www.boost.org/development/tests/develop/developer/phoenix.html">http://www.boost.org/development/tests/develop/developer/phoenix.html</a> </p> <p> When it runs O.K. I will move it to master, hopefully in time for 1.56.0. </p> <p> When I cannot see a general fix I am fixing for C++11 only. </p> <p> John </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Kohei Takahashi</dc:creator> <pubDate>Sat, 13 May 2017 06:47:32 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8704#comment:5 https://svn.boost.org/trac10/ticket/8704#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">fixed</span> </li> </ul> Ticket