Boost C++ Libraries: Ticket #1821: lambda and transform_iterator https://svn.boost.org/trac10/ticket/1821 <p> This code doesn't compile. </p> <pre class="wiki">#include &lt;utility&gt; #include &lt;list&gt; #include &lt;boost\iterator\transform_iterator.hpp&gt; #include &lt;boost\lambda\lambda.hpp&gt; #include &lt;boost\lambda\bind.hpp&gt; #include &lt;boost\function.hpp&gt; int main(int argc, char* argv[]) { using namespace std; using namespace boost; using namespace boost::lambda; typedef list&lt;pair&lt;int, double&gt; &gt; Tlist; make_transform_iterator ( Tlist().begin(), bind(&amp;Tlist::value_type::first, _1) ); return 0; } </pre><hr /> <p> But this does: </p> <pre class="wiki">#include &lt;utility&gt; #include &lt;list&gt; #include &lt;boost\iterator\transform_iterator.hpp&gt; #include &lt;boost\lambda\lambda.hpp&gt; #include &lt;boost\lambda\bind.hpp&gt; #include &lt;boost\function.hpp&gt; int main(int argc, char* argv[]) { using namespace std; using namespace boost; using namespace boost::lambda; typedef list&lt;pair&lt;int, double&gt; &gt; Tlist; make_transform_iterator ( Tlist().begin(), function&lt;int(Tlist::value_type)&gt; ( bind(&amp;Tlist::value_type::first, _1) ) ); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1821 Trac 1.4.3 Dave Abrahams Sun, 13 Apr 2008 00:53:08 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1821#comment:1 https://svn.boost.org/trac10/ticket/1821#comment:1 <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> The type of your bind expression does not satisfy the requirements of <code>transform_iterator</code> as described in <a class="ext-link" href="http://boost.org/doc/libs/1_35_0/libs/iterator/doc/transform_iterator.html#transform-iterator-requirements"><span class="icon">​</span>http://boost.org/doc/libs/1_35_0/libs/iterator/doc/transform_iterator.html#transform-iterator-requirements</a> </p> <p> In particular, the expression <code>result_of&lt;UnaryFunction(iterator_traits&lt;Iterator&gt;::reference)&gt;::type</code> is not valid. This will all get better in C++0x when we have decltype, but in the meantime, it can't be considered a bug in Boost.Iterator. </p> Ticket anonymous Tue, 18 Sep 2012 22:48:31 GMT <link>https://svn.boost.org/trac10/ticket/1821#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1821#comment:2</guid> <description> <p> now that we have decltype, should transform_iterator be adapated to take lambda expressions? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 12 Nov 2012 10:35:48 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1821#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1821#comment:3</guid> <description> <p> Supporting lambdas would be of great benefit. I was quite surprised to find they weren't supported. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Michel Morin</dc:creator> <pubDate>Mon, 12 Nov 2012 15:06:12 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/1821#comment:4 https://svn.boost.org/trac10/ticket/1821#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> Ticket Michel Morin Mon, 12 Nov 2012 15:07:17 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1821#comment:5 https://svn.boost.org/trac10/ticket/1821#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Already fixed in Boost 1.47. </p> <p> This ticket is a composite of </p> <ul><li><a class="closed ticket" href="https://svn.boost.org/trac10/ticket/864" title="#864: Patches: [lambda][utility] Make lambda support result&lt;&gt; (closed: fixed)">#864</a>: Make lambda support result&lt;&gt; </li><li><a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1427" title="#1427: Feature Requests: [iterator] transform_iterator should use boost::result_of to determine ... (closed: fixed)">#1427</a>: transform_iterator should use boost/result_of to determine functor result type </li></ul><p> which were fixed in Boost 1.44 and 1.47, respectively. </p> <p> P.S. This ticket is about Boost.Lambda and NOT about C++11 lambdas. For C++11 lambdas, you should use decltype-based result_of. Please read <a href="http://www.boost.org/doc/libs/release/libs/utility/utility.htm#result_of">result_of doc</a> (especially about <strong><code>BOOST_RESULT_OF_USE_DECLTYPE</code></strong> macro). </p> Ticket