mirror of
https://github.com/boostorg/optional.git
synced 2025-06-28 21:41:09 +02:00
Compare commits
5 Commits
svn-branch
...
boost-1.30
Author | SHA1 | Date | |
---|---|---|---|
ac7a7a9d15 | |||
929847570c | |||
63a928a510 | |||
650b4a89b3 | |||
f8fb254fff |
@ -191,15 +191,15 @@ bool operator != ( optional<T> const& lhs, optional<T> const&
|
|||||||
<P>This meaning of the null pointer value allowed pointers to became a defacto standard
|
<P>This meaning of the null pointer value allowed pointers to became a defacto standard
|
||||||
for handling optional objects because all you have to do to refer to a value which you
|
for handling optional objects because all you have to do to refer to a value which you
|
||||||
don't really have is to use a null pointer value of the appropriate type.
|
don't really have is to use a null pointer value of the appropriate type.
|
||||||
Pointers have been used for decades -from the days of C APIs to modern C++ libraries-
|
Pointers have been used for decades—from the days of C APIs to modern C++ libraries—to
|
||||||
to <i>refer</i> to optional (that is, possibly inexistent) objects; particularly
|
<i>refer</i> to optional (that is, possibly inexistent) objects; particularly
|
||||||
as optional arguments to a function, but also quite often as optional data members.</P>
|
as optional arguments to a function, but also quite often as optional data members.</P>
|
||||||
<P>The possible presence of a null pointer value makes the operations that access the
|
<P>The possible presence of a null pointer value makes the operations that access the
|
||||||
pointee's value possibly undefined, therefore, expressions which use dereference
|
pointee's value possibly undefined, therefore, expressions which use dereference
|
||||||
and access operators, such as: <code>( *p = 2 )</code> and <code>( p->foo())</code>,
|
and access operators, such as: <code>( *p = 2 )</code> and <code>( p->foo())</code>,
|
||||||
implicitly convey the notion of optionality, and this information is tied to
|
implicitly convey the notion of optionality, and this information is tied to
|
||||||
the <i>syntax</i> of the expressions. That is, the presence of operators * and -> tell by
|
the <i>syntax</i> of the expressions. That is, the presence of operators * and -> tell by
|
||||||
themselves -without any additional context-, that the expression will be undefined unless
|
themselves—without any additional context—that the expression will be undefined unless
|
||||||
the implied pointee actually exist.<br>
|
the implied pointee actually exist.<br>
|
||||||
Furthermore, the existence of the pointee can be tested by a comparison against
|
Furthermore, the existence of the pointee can be tested by a comparison against
|
||||||
the null pointer value or via a conversion to bool, which allows expressions of
|
the null pointer value or via a conversion to bool, which allows expressions of
|
||||||
@ -228,7 +228,7 @@ them. The problem resides in the shallow-copy of pointer semantics: if you need
|
|||||||
possible undefined value because of the idiomatic aid present in the OptionalPointee
|
possible undefined value because of the idiomatic aid present in the OptionalPointee
|
||||||
concept incarnated by pointers. <br>
|
concept incarnated by pointers. <br>
|
||||||
Therefore, the final solution which is presented in this library is to shape the
|
Therefore, the final solution which is presented in this library is to shape the
|
||||||
previously discussed optional -which is a value-based container- as a model
|
previously discussed optional—which is a value-based container—as a model
|
||||||
of the OptionalPointee concept.
|
of the OptionalPointee concept.
|
||||||
</p>
|
</p>
|
||||||
<h3>Optional<T> as a model of OptionalPointee</h3>
|
<h3>Optional<T> as a model of OptionalPointee</h3>
|
||||||
@ -806,14 +806,13 @@ class Fred
|
|||||||
|
|
||||||
<H2><A NAME="bool">A note about optional<bool></A></H2>
|
<H2><A NAME="bool">A note about optional<bool></A></H2>
|
||||||
<p><code>optional<bool></code> should be used with special caution and consideration.</p>
|
<p><code>optional<bool></code> should be used with special caution and consideration.</p>
|
||||||
<p>First, it is functionally similar to a tristate boolean (false,maybe,true)
|
<p>First, it is functionally similar to a tristate boolean (false,maybe,true) —such as
|
||||||
-such as <u>boost::tribool</u> (not yet formally in boost)-,
|
<u>boost::tribool</u> (not yet formally in boost)—except that in a tristate boolean,
|
||||||
except that in a tristate boolean, the <i>maybe</i> state
|
the <i>maybe</i> state <u>represents a valid value</u>, unlike the corresponding state
|
||||||
<u>represents a valid value</u>, unlike the corresponding state
|
|
||||||
of an uninitialized optional<bool>.<br>
|
of an uninitialized optional<bool>.<br>
|
||||||
It should be carefully considered if an optional bool instead of a tribool is really needed</p>
|
It should be carefully considered if an optional bool instead of a tribool is really needed</p>
|
||||||
<p>Second, optional<> provides and implicit conversion to bool. This conversion
|
<p>Second, optional<> provides an implicit conversion to bool. This conversion
|
||||||
refers to the initialization state and not to the contained value.<br>
|
refers to the initialization state and not to the contained value.<br>
|
||||||
Using optional<bool> can lead to subtle errors due to the implicit bool conversion:</p>
|
Using optional<bool> can lead to subtle errors due to the implicit bool conversion:</p>
|
||||||
<pre>
|
<pre>
|
||||||
void foo ( bool v ) ;
|
void foo ( bool v ) ;
|
||||||
@ -978,6 +977,6 @@ HREF="http://www.boost.org">www.boost.org</A>, and the boost discussion list at
|
|||||||
<A
|
<A
|
||||||
HREF="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</A>.
|
HREF="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</A>.
|
||||||
</P>
|
</P>
|
||||||
</u></BODY>
|
</BODY>
|
||||||
</HTML>
|
</HTML>
|
||||||
|
|
||||||
|
@ -57,7 +57,8 @@ namespace boost
|
|||||||
union dummy_u
|
union dummy_u
|
||||||
{
|
{
|
||||||
char data[ sizeof(T) ];
|
char data[ sizeof(T) ];
|
||||||
type_with_alignment< ::boost::alignment_of<T>::value > aligner_;
|
BOOST_DEDUCED_TYPENAME type_with_alignment<
|
||||||
|
::boost::alignment_of<T>::value >::type aligner_;
|
||||||
} dummy_ ;
|
} dummy_ ;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user