Boost C++ Libraries: Ticket #7330: Patch adding move constructors and move assignments https://svn.boost.org/trac10/ticket/7330 <p> Use of move constructor and move assignment reduce memory allocation/deallocations count and do not call functor copy operator for big functors. Example: </p> <pre class="wiki">struct big_aggregating_structure { int disable_small_objects_optimizations[32]; void operator()() {} }; ... function&lt;void()&gt; f1 = big_aggregating_structure(); function&lt;void()&gt; f2 = f1; // will call new, copy() function&lt;void()&gt; f3 = std::move(f1); // Just swaps pointers, leaves f1 empty f3 = f2; // Will call new, copy(), destory(), delete f3 = std::move(f2); // Just swaps pointers, leaves f2 empty (calls destory(), delete for f3) { function&lt;void()&gt; f_new1 = big_aggregating_structure(); function&lt;void()&gt; f_new2 = std::move(f_new1); // Without move constructor, there will be additional new, copy(), destroy(), delete calls } </pre><p> This patch could be very usefull for boost::asio, boost::thread and anyone, who uses boost::function in STL containers on C++11 compilers. Patch was tested on MSVC2010, GCC-4.6 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7330 Trac 1.4.3 Antony Polukhin Wed, 05 Sep 2012 18:31:00 GMT attachment set https://svn.boost.org/trac10/ticket/7330 https://svn.boost.org/trac10/ticket/7330 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">function_template.hpp.diff</span> </li> </ul> Ticket Antony Polukhin Wed, 05 Sep 2012 18:31:18 GMT attachment set https://svn.boost.org/trac10/ticket/7330 https://svn.boost.org/trac10/ticket/7330 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">function_test.cpp.diff</span> </li> </ul> Ticket Antony Polukhin Mon, 17 Sep 2012 04:08:21 GMT <link>https://svn.boost.org/trac10/ticket/7330#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7330#comment:1</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/80552" title="Add move assignment and move constructors to Boost.Function (refs #7330)">[80552]</a>) Add move assignment and move constructors to Boost.Function (refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7330" title="#7330: Patches: Patch adding move constructors and move assignments (closed: fixed)">#7330</a>) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Fri, 28 Sep 2012 18:14:02 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7330#comment:2 https://svn.boost.org/trac10/ticket/7330#comment:2 <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> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/80738" title="Merge from trunk: added move assignment and move constructors to ...">[80738]</a>) Merge from trunk: added move assignment and move constructors to Boost.Function (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7330" title="#7330: Patches: Patch adding move constructors and move assignments (closed: fixed)">#7330</a>) </p> Ticket