Boost C++ Libraries: Ticket #1841: Optional: C++0x features https://svn.boost.org/trac10/ticket/1841 <p> There are a couple of features in C++0x that would be very useful in the optional library. First is the emplace function (see <a class="ext-link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2345.pdf"><span class="icon">​</span>http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2345.pdf</a>). This is how the C++0x containers will do in-place construction; optional should allow it as well so the same operation can be done in the same way. One issue is what to do if we call emplace on an optional that is not empty. We could assert, throw an exception, reset and then construct in-place, or construct out-of-place and then swap. Personally I prefer the third option. </p> <p> Second, optional should make use of rvalue-references where available. Note that if swap() were implemented using the move constructor and move assignment operator, then it would just do the right thing with respect to iterators to the standard containers. </p> <pre class="wiki">template&lt;class T&gt; inline void optional_swap ( optional&lt;T&gt;&amp; x, optional&lt;T&gt;&amp; y ) { if ( !x &amp;&amp; !!y ) { x.reset(std::move(*y)); y.reset(); } else if ( !!x &amp;&amp; !y ) { y.reset(std::move(*x)); x.reset(); } else if ( !!x &amp;&amp; !!y ) { // GCC &gt; 3.2 and all other compilers have the using declaration at function scope (FLC) #ifndef BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE // allow for Koenig lookup using std::swap ; #endif swap(*x,*y); } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1841 Trac 1.4.3 mlcreech@… Fri, 04 Feb 2011 20:54:46 GMT <link>https://svn.boost.org/trac10/ticket/1841#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:1</guid> <description> <p> Are there any plans to add support for rvalue references to boost::optional? This makes a very big difference on C++0x code. </p> <p> Also, bug severity should not be "optimization" - as things are, classes which are movable but not copyable can't be used at all with boost::optional (compile errors), whereas if move semantics were respected it would work fine. </p> </description> <category>Ticket</category> </item> <item> <author>mlcreech@…</author> <pubDate>Fri, 04 Feb 2011 22:17:59 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/1841 https://svn.boost.org/trac10/ticket/1841 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">14-optional-partial-rvalue.patch</span> </li> </ul> <p> Partial move support </p> Ticket mlcreech@… Fri, 04 Feb 2011 22:19:25 GMT <link>https://svn.boost.org/trac10/ticket/1841#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:2</guid> <description> <p> I've attached an example patch which fixes my build problems when using boost::optional with noncopyable objects. It doesn't handle move semantics for boost::optional objects themselves, but does for the underlying type. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>NN</dc:creator> <pubDate>Wed, 09 Feb 2011 12:40:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1841#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:3</guid> <description> <p> I support this patch. C++0x move feature makes code much better optimized ! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Fernando Cacciola</dc:creator> <pubDate>Thu, 17 Feb 2011 13:26:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1841#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:4</guid> <description> <p> I will be working on adding this next week or the one after. </p> <p> Best </p> </description> <category>Ticket</category> </item> <item> <author>boost@…</author> <pubDate>Mon, 05 Dec 2011 07:33:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1841#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:5</guid> <description> <p> Hi, I stumbled across this ticket while looking for a solution for the same issues with move-only types in Boost.Optional, will there be a fix anytime near in the future? </p> <p> Regards, Arne </p> </description> <category>Ticket</category> </item> <item> <author>mlcreech@…</author> <pubDate>Mon, 05 Dec 2011 13:06:22 GMT</pubDate> <title>version, type, severity changed https://svn.boost.org/trac10/ticket/1841#comment:6 https://svn.boost.org/trac10/ticket/1841#comment:6 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.35.0</span> → <span class="trac-field-new">Boost 1.38.0</span> </li> <li><strong>type</strong> <span class="trac-field-old">Feature Requests</span> → <span class="trac-field-new">Patches</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Optimization</span> → <span class="trac-field-new">Problem</span> </li> </ul> <p> Arne, does this patch work for you? It at least fixed the build problems I was having. I'm still using it with 1.48, I'll post an updated version. </p> <p> I'm going to change the type/severity also: this problem prevents code from building which should otherwise work when move semantics are enabled. </p> Ticket mlcreech@… Mon, 05 Dec 2011 13:07:06 GMT attachment set https://svn.boost.org/trac10/ticket/1841 https://svn.boost.org/trac10/ticket/1841 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">14-optional-partial-rvalue.2.patch</span> </li> </ul> <p> Updated patch for 1.48 </p> Ticket Fernando Cacciola Fri, 13 Jan 2012 02:42:05 GMT status changed https://svn.boost.org/trac10/ticket/1841#comment:7 https://svn.boost.org/trac10/ticket/1841#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I started work on this </p> Ticket jmckesson@… Mon, 09 Jul 2012 04:38:25 GMT version changed https://svn.boost.org/trac10/ticket/1841#comment:8 https://svn.boost.org/trac10/ticket/1841#comment:8 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.38.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Is this going to be implemented anytime soon? </p> Ticket tjackson@… Thu, 11 Oct 2012 19:14:05 GMT <link>https://svn.boost.org/trac10/ticket/1841#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:9</guid> <description> <p> I'd love to see this completed. Any updates? </p> </description> <category>Ticket</category> </item> <item> <author>zeratul976@…</author> <pubDate>Sun, 21 Oct 2012 07:52:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1841#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:10</guid> <description> <p> +1, I'd like to see this as well! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Fernando Cacciola</dc:creator> <pubDate>Mon, 22 Oct 2012 13:03:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1841#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:11</guid> <description> <p> I (re)-started working on it this week. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Mozza314</dc:creator> <pubDate>Thu, 21 Mar 2013 01:10:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1841#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:12</guid> <description> <p> +1 Surely this is a no-brainer. optional should take advantage of move semantics. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Lindley</dc:creator> <pubDate>Thu, 24 Oct 2013 18:33:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1841#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1841#comment:13</guid> <description> <p> This still appears to be unfixed in 1.54. This needs to get done. </p> <p> As it stands now, this bug prevents the Signals2 library from being used with a move-only return value from a slot such as a std::future, among other things. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>akrzemi1</dc:creator> <pubDate>Fri, 06 Jun 2014 11:30:56 GMT</pubDate> <title>owner, status, version, milestone changed https://svn.boost.org/trac10/ticket/1841#comment:14 https://svn.boost.org/trac10/ticket/1841#comment:14 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Fernando Cacciola</span> to <span class="trac-author">akrzemi1</span> </li> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">new</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.50.0</span> → <span class="trac-field-new">Boost 1.56.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.56.0</span> </li> </ul> Ticket akrzemi1 Fri, 06 Jun 2014 11:32:26 GMT status, version changed; resolution set https://svn.boost.org/trac10/ticket/1841#comment:15 https://svn.boost.org/trac10/ticket/1841#comment:15 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.56.0</span> → <span class="trac-field-new">Boost 1.36.0</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> move semantics, improved swap and function emplace() added in branch master. </p> Ticket