<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: boost::optional and its internals</title>
	<atom:link href="http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/feed/" rel="self" type="application/rss+xml" />
	<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/</link>
	<description>Discussing modern C++ and related topics.</description>
	<lastBuildDate>Tue, 31 Jan 2012 01:36:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Iain Fraser</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-703</link>
		<dc:creator><![CDATA[Iain Fraser]]></dc:creator>
		<pubDate>Wed, 14 Sep 2011 18:10:01 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-703</guid>
		<description><![CDATA[great article man]]></description>
		<content:encoded><![CDATA[<p>great article man</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rmn</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-469</link>
		<dc:creator><![CDATA[rmn]]></dc:creator>
		<pubDate>Wed, 12 May 2010 20:15:44 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-469</guid>
		<description><![CDATA[Hi Or,
First off, thanks for the correct comments.
It is important to keep in mind that this post only introduces a proof-of-concept for the proposed optional mechanism; As stated, it does not provide a full implementation.

However, the issues you have raised can be addressed:
1. Assuming T::operator= is itself exception safe, we could alter the implementation of our operator= to delegate the assignment to T::operator= if the optional is initialized. Note that by doing so we place a (new!) requirement on T: it now has to provide a public assignment operator. Another thing to think about is this: is that the behaviour you would want from an optional construct like this one? I am not sure.
2. It is true. However, keep in mind that the nature of the problem we started with was that of an object we would like to return by value from a function. It is unlikely to use any resources in a RAII fashion.
3. This problem is indeed a known one and is addressed at the end of the article. I would strongly advice you to have a look at how the folks at Boost have tackled the problem.

Thanks for the insightful comments!]]></description>
		<content:encoded><![CDATA[<p>Hi Or,<br />
First off, thanks for the correct comments.<br />
It is important to keep in mind that this post only introduces a proof-of-concept for the proposed optional mechanism; As stated, it does not provide a full implementation.</p>
<p>However, the issues you have raised can be addressed:<br />
1. Assuming T::operator= is itself exception safe, we could alter the implementation of our operator= to delegate the assignment to T::operator= if the optional is initialized. Note that by doing so we place a (new!) requirement on T: it now has to provide a public assignment operator. Another thing to think about is this: is that the behaviour you would want from an optional construct like this one? I am not sure.<br />
2. It is true. However, keep in mind that the nature of the problem we started with was that of an object we would like to return by value from a function. It is unlikely to use any resources in a RAII fashion.<br />
3. This problem is indeed a known one and is addressed at the end of the article. I would strongly advice you to have a look at how the folks at Boost have tackled the problem.</p>
<p>Thanks for the insightful comments!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Or</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-444</link>
		<dc:creator><![CDATA[Or]]></dc:creator>
		<pubDate>Tue, 27 Apr 2010 22:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-444</guid>
		<description><![CDATA[Roman, now I noticed that there is a slight problem with the posted code:
1). It&#039;s not exception-safe: it fails to obey the strong guarantee(i.e the program is inconsistent when an exception is thrown).
operator= (const  optional &amp;opt) is exception-unsafe:
If the construct operation throws then the program is in inconsistent state as we stay with a destroyed object(instead of staying in the previous normal state).
2). object lifetime playing is not always good, it is tricky, suppose T has a mutex object(which uses RAII) then we could have a potential hard to detect race condition(as the construct and destruct operation are not atomic).
3). The more serious problem is that stack allocated buffer is not guaranteed to be aligned, thus it can trigger a hardware exception when you try to access T&#039;s member.

So as the buffer array solved some problems(we postpone T initialization and don&#039;t use dynamic memory allocation) it also created new evil ones.

Thanks!]]></description>
		<content:encoded><![CDATA[<p>Roman, now I noticed that there is a slight problem with the posted code:<br />
1). It&#8217;s not exception-safe: it fails to obey the strong guarantee(i.e the program is inconsistent when an exception is thrown).<br />
operator= (const  optional &amp;opt) is exception-unsafe:<br />
If the construct operation throws then the program is in inconsistent state as we stay with a destroyed object(instead of staying in the previous normal state).<br />
2). object lifetime playing is not always good, it is tricky, suppose T has a mutex object(which uses RAII) then we could have a potential hard to detect race condition(as the construct and destruct operation are not atomic).<br />
3). The more serious problem is that stack allocated buffer is not guaranteed to be aligned, thus it can trigger a hardware exception when you try to access T&#8217;s member.</p>
<p>So as the buffer array solved some problems(we postpone T initialization and don&#8217;t use dynamic memory allocation) it also created new evil ones.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rmn</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-386</link>
		<dc:creator><![CDATA[rmn]]></dc:creator>
		<pubDate>Fri, 23 Apr 2010 20:39:06 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-386</guid>
		<description><![CDATA[If you refer to the signatures of the copy constructor and the assignment operator, it was done as a kind of documentation; In a complete implementation I would add a constructor to build an optional&lt;T&gt; from any related optional&lt;U&gt; such that there&#039;s a conversion from U to T. And the same goes for operator=. Since I left that out, I felt it would be better to leave an explicit reminder of the matter.
Essentially, you are correct. Thanks for the comment.]]></description>
		<content:encoded><![CDATA[<p>If you refer to the signatures of the copy constructor and the assignment operator, it was done as a kind of documentation; In a complete implementation I would add a constructor to build an optional&lt;T&gt; from any related optional&lt;U&gt; such that there&#8217;s a conversion from U to T. And the same goes for operator=. Since I left that out, I felt it would be better to leave an explicit reminder of the matter.<br />
Essentially, you are correct. Thanks for the comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Or</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-380</link>
		<dc:creator><![CDATA[Or]]></dc:creator>
		<pubDate>Tue, 20 Apr 2010 22:11:49 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-380</guid>
		<description><![CDATA[I think the angle bracket with the T in between is unnecessary, as we know we are dealing with the T instantiation.
I think it&#039;s a good implementation and it somehow reminds me the famous sentence &quot;We can solve any problem by introducing an extra level of indirection.&quot;.]]></description>
		<content:encoded><![CDATA[<p>I think the angle bracket with the T in between is unnecessary, as we know we are dealing with the T instantiation.<br />
I think it&#8217;s a good implementation and it somehow reminds me the famous sentence &#8220;We can solve any problem by introducing an extra level of indirection.&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rmn</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-312</link>
		<dc:creator><![CDATA[rmn]]></dc:creator>
		<pubDate>Sun, 28 Feb 2010 20:59:47 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-312</guid>
		<description><![CDATA[boost::optional is part of the boost libraries: http://www.boost.org/

Luckily, it is a header-only utility, which means that you don&#039;t have to link with anything. All you have to do is: [sourcecode language=&quot;cpp&quot;]#include &lt;boost/optional.hpp&gt;[/sourcecode]

Alternatively, you could use the implementation I have provided in this post - if it is good enough for your needs.]]></description>
		<content:encoded><![CDATA[<p>boost::optional is part of the boost libraries: <a href="http://www.boost.org/" rel="nofollow">http://www.boost.org/</a></p>
<p>Luckily, it is a header-only utility, which means that you don&#8217;t have to link with anything. All you have to do is:
<pre class="brush: cpp;">#include &lt;boost/optional.hpp&gt;</pre>
<p>Alternatively, you could use the implementation I have provided in this post &#8211; if it is good enough for your needs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dav</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-307</link>
		<dc:creator><![CDATA[dav]]></dc:creator>
		<pubDate>Sun, 21 Feb 2010 15:05:05 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-307</guid>
		<description><![CDATA[Which library do I need to link that includes boost::optional?
I&#039;ve getting: undefined reference to `boost::optional etc...]]></description>
		<content:encoded><![CDATA[<p>Which library do I need to link that includes boost::optional?<br />
I&#8217;ve getting: undefined reference to `boost::optional etc&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rmn</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-295</link>
		<dc:creator><![CDATA[rmn]]></dc:creator>
		<pubDate>Mon, 08 Feb 2010 18:39:41 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-295</guid>
		<description><![CDATA[Ofcourse! How could I forget &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/7e10dcw5(VS.80).aspx&quot; rel=&quot;nofollow&quot;&gt;map::mapped_type&lt;/a&gt;?

Should be fixed now.]]></description>
		<content:encoded><![CDATA[<p>Ofcourse! How could I forget <a href="http://msdn.microsoft.com/en-us/library/7e10dcw5(VS.80).aspx" rel="nofollow">map::mapped_type</a>?</p>
<p>Should be fixed now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manuel</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-294</link>
		<dc:creator><![CDATA[Manuel]]></dc:creator>
		<pubDate>Mon, 08 Feb 2010 18:31:52 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-294</guid>
		<description><![CDATA[Thanks for fixing the formatting of my code (I didn&#039;t know what tags to use) but I&#039;m afraid some of changes you&#039;ve made are not quite right. This is how it should look like:

http://pastie.org/814956

Please notice that there&#039;s no need for &quot;V&quot; as a template parameter. 

Best regards]]></description>
		<content:encoded><![CDATA[<p>Thanks for fixing the formatting of my code (I didn&#8217;t know what tags to use) but I&#8217;m afraid some of changes you&#8217;ve made are not quite right. This is how it should look like:</p>
<p><a href="http://pastie.org/814956" rel="nofollow">http://pastie.org/814956</a></p>
<p>Please notice that there&#8217;s no need for &#8220;V&#8221; as a template parameter. </p>
<p>Best regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rmn</title>
		<link>http://cplusplus.co.il/2009/12/04/boost-optional-and-its-internals/#comment-292</link>
		<dc:creator><![CDATA[rmn]]></dc:creator>
		<pubDate>Mon, 08 Feb 2010 18:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://cplusplus.co.il/?p=623#comment-292</guid>
		<description><![CDATA[Boost as a whole is indeed pretty great, and also this very neat utility class.

I&#039;ve taken the liberty to slightly edit your post to use the &#039;sourcecode&#039; tags and re-added the &#039;&gt;&#039; and &#039;&lt;&#039; characters, which have been lost. I hope you don&#039;t mind and that I haven&#039;t messed anything up. Let me know if I did.

Thanks for the kind words.]]></description>
		<content:encoded><![CDATA[<p>Boost as a whole is indeed pretty great, and also this very neat utility class.</p>
<p>I&#8217;ve taken the liberty to slightly edit your post to use the &#8216;sourcecode&#8217; tags and re-added the &#8216;&gt;&#8217; and &#8216;&lt;&#39; characters, which have been lost. I hope you don&#39;t mind and that I haven&#39;t messed anything up. Let me know if I did.</p>
<p>Thanks for the kind words.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

