Boost C++ Libraries: Ticket #4969: transform_iterator won't work with non-const operator() call for function object https://svn.boost.org/trac10/ticket/4969 <p> transform_iterator declare it's copied function object as: </p> <div class="wiki-code"><div class="code"><pre> <span class="n">UnaryFunc</span> <span class="n">m_f</span><span class="p">;</span> </pre></div></div><p> And it's dereference function as: </p> <div class="wiki-code"><div class="code"><pre> <span class="k">typename</span> <span class="n">super_t</span><span class="o">::</span><span class="n">reference</span> <span class="n">dereference</span><span class="p">()</span> <span class="k">const</span> <span class="p">{</span> <span class="k">return</span> <span class="n">m_f</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="o">-&gt;</span><span class="n">base</span><span class="p">());</span> <span class="p">}</span> </pre></div></div><p> which makes it impossible to cooperate with function object with non-const operator() overloading, and and it will also make transformed adaptor in boost::range not work: </p> <div class="wiki-code"><div class="code"><pre><span class="k">struct</span> <span class="n">Fun</span> <span class="p">{</span> <span class="k">typedef</span> <span class="kt">bool</span> <span class="n">result_type</span><span class="p">;</span> <span class="kt">bool</span> <span class="nf">operator</span><span class="p">()(</span><span class="kt">int</span> <span class="n">a</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">a</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">;</span> <span class="p">}</span> <span class="p">};</span> <span class="n">Fun</span> <span class="n">f</span><span class="p">;</span> <span class="n">boost</span><span class="o">::</span><span class="n">find</span><span class="p">(</span><span class="n">all</span><span class="o">|</span><span class="n">boost</span><span class="o">::</span><span class="n">adaptors</span><span class="o">::</span><span class="n">transformed</span><span class="p">(</span><span class="n">f</span><span class="p">),</span> <span class="nb">true</span><span class="p">);</span> </pre></div></div><p> A boost::ref won't work here since the result has no result_type defined </p> <p> And the only solution would be using a boost::function to hold the original function object, however, doing so will give unnecessary run time cost. </p> <p> I suggest change the <a class="missing wiki">UnaryFunc</a> m_f; definition to mutable, so that it will work with non-const functor. </p> <div class="wiki-code"><div class="code"><pre> <span class="n">UnaryFunc</span> <span class="k">mutable</span> <span class="n">m_f</span><span class="p">;</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4969 Trac 1.4.3 prabhu.swain@… Mon, 13 Dec 2010 10:00:47 GMT cc set https://svn.boost.org/trac10/ticket/4969#comment:1 https://svn.boost.org/trac10/ticket/4969#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">prabhu.swain@…</span> added </li> </ul> Ticket prabhu.swain@… Mon, 13 Dec 2010 10:03:35 GMT cc deleted https://svn.boost.org/trac10/ticket/4969#comment:2 https://svn.boost.org/trac10/ticket/4969#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">prabhu.swain@…</span> removed </li> </ul> Ticket Dave Abrahams Wed, 21 Nov 2012 19:44:59 GMT owner changed https://svn.boost.org/trac10/ticket/4969#comment:3 https://svn.boost.org/trac10/ticket/4969#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Dave Abrahams</span> to <span class="trac-author">jeffrey.hellrung</span> </li> </ul> Ticket anonymous Sun, 23 Feb 2014 16:18:00 GMT <link>https://svn.boost.org/trac10/ticket/4969#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4969#comment:4</guid> <description> <p> Please prioritize this ticket. With C++11 mutable lambdas (for which the Standard mandates a non-const operator()) this problem becomes much more frequent. </p> </description> <category>Ticket</category> </item> </channel> </rss>