Compare commits
27 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
070958fa84 | |||
e68e68276c | |||
e14e0fc3ba | |||
101bb76c18 | |||
5a1938ccf7 | |||
4c11dcc703 | |||
eb19cc2729 | |||
5956702c32 | |||
4ba562871e | |||
4669cd828c | |||
3ff4258fbb | |||
35040aab6a | |||
bfd5cc0a87 | |||
0fd45d73b1 | |||
3bf8d0f1b4 | |||
789cb2b24f | |||
7287f2bf11 | |||
b6a1946a60 | |||
9bbde2be14 | |||
f258713788 | |||
3dc3f46d66 | |||
c23c21d9c2 | |||
5182283649 | |||
4599ae0bfd | |||
9ccefc8349 | |||
0961a6598a | |||
03248b5fd8 |
@ -1,22 +0,0 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# This file was automatically generated from the original CMakeLists.txt file
|
||||
# Add a variable to hold the headers for the library
|
||||
set (lib_headers
|
||||
optional.hpp
|
||||
optional
|
||||
)
|
||||
|
||||
# Add a library target to the build system
|
||||
boost_library_project(
|
||||
optional
|
||||
# SRCDIRS
|
||||
TESTDIRS test
|
||||
HEADERS ${lib_headers}
|
||||
DOCDIRS doc
|
||||
# DESCRIPTION
|
||||
MODULARIZED
|
||||
# AUTHORS
|
||||
# MAINTAINERS
|
||||
)
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
boost_add_documentation(optional.qbk)
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
import quickbook ;
|
||||
|
||||
path-constant images : html ;
|
||||
|
||||
xml optional
|
||||
:
|
||||
optional.qbk
|
||||
@ -28,8 +26,5 @@ boostbook standalone
|
||||
<xsl:param>toc.max.depth=2
|
||||
<xsl:param>toc.section.depth=2
|
||||
<xsl:param>chunk.section.depth=1
|
||||
<format>pdf:<xsl:param>img.src.path=$(images)/
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/optional/doc/html
|
||||
;
|
||||
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>A note about optional<bool></title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="in_place_factories.html" title="In-Place Factories">
|
||||
<link rel="next" href="exception_safety_guarantees.html" title="Exception Safety Guarantees">
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Acknowledgments</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="dependencies_and_portability.html" title="Dependencies and Portability">
|
||||
</head>
|
||||
@ -26,7 +26,7 @@
|
||||
<a name="boost_optional.acknowledgments"></a><a class="link" href="acknowledgments.html" title="Acknowledgments">Acknowledgments</a>
|
||||
</h2></div></div></div>
|
||||
<a name="boost_optional.acknowledgments.pre_formal_review"></a><h4>
|
||||
<a name="id704954"></a>
|
||||
<a name="id2865262"></a>
|
||||
<a class="link" href="acknowledgments.html#boost_optional.acknowledgments.pre_formal_review">Pre-formal
|
||||
review</a>
|
||||
</h4>
|
||||
@ -65,7 +65,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<a name="boost_optional.acknowledgments.post_formal_review"></a><h4>
|
||||
<a name="id705000"></a>
|
||||
<a name="id2865331"></a>
|
||||
<a class="link" href="acknowledgments.html#boost_optional.acknowledgments.post_formal_review">Post-formal
|
||||
review</a>
|
||||
</h4>
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Dependencies and Portability</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="implementation_notes.html" title="Implementation Notes">
|
||||
<link rel="next" href="acknowledgments.html" title="Acknowledgments">
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Detailed Semantics</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="synopsis.html" title="Synopsis">
|
||||
<link rel="next" href="examples.html" title="Examples">
|
||||
@ -64,7 +64,7 @@
|
||||
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<a name="boost_optional.detailed_semantics.optional_class_member_functions"></a><h4>
|
||||
<a name="id677650"></a>
|
||||
<a name="id2841077"></a>
|
||||
<a class="link" href="detailed_semantics.html#boost_optional.detailed_semantics.optional_class_member_functions">optional
|
||||
class member functions</a>
|
||||
</h4>
|
||||
@ -499,7 +499,7 @@
|
||||
constructor called by the factory throws.
|
||||
</li>
|
||||
<li>
|
||||
<span class="bold"><strong>Notes:</strong></span> See <a class="link" href="in_place_factories.html" title="In-Place Factories">In-Place
|
||||
<span class="bold"><strong>Notes:</strong></span> See <a class="link" href="../index.html#optional_in_place_factories">In-Place
|
||||
Factories</a>
|
||||
</li>
|
||||
<li>
|
||||
@ -604,8 +604,8 @@
|
||||
</li>
|
||||
<li>
|
||||
<span class="bold"><strong>Notes:</strong></span> If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> was initialized, is is <span class="emphasis"><em>rebound</em></span>
|
||||
to the new object. See <a class="link" href="rebinding_semantics_for_assignment_of_optional_references.html" title="Rebinding semantics for assignment of optional references">here</a>
|
||||
for details on this behavior.
|
||||
to the new object. See <a class="link" href="../index.html#optional_refassign">here</a> for
|
||||
details on this behavior.
|
||||
</li>
|
||||
<li>
|
||||
<span class="bold"><strong>Example:</strong></span><pre class="programlisting"><span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">1</span> <span class="special">;</span>
|
||||
@ -710,7 +710,7 @@
|
||||
</li>
|
||||
<li>
|
||||
<span class="bold"><strong>Notes:</strong></span> If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> was initialized and so is *rhs, this
|
||||
is is <span class="emphasis"><em>rebound</em></span> to the new object. See <a class="link" href="rebinding_semantics_for_assignment_of_optional_references.html" title="Rebinding semantics for assignment of optional references">here</a>
|
||||
is is <span class="emphasis"><em>rebound</em></span> to the new object. See <a class="link" href="../index.html#optional_refassign">here</a>
|
||||
for details on this behavior.
|
||||
</li>
|
||||
<li>
|
||||
@ -1319,7 +1319,7 @@
|
||||
<span class="inlinemediaobject"><img src="../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<a name="boost_optional.detailed_semantics.free_functions"></a><h4>
|
||||
<a name="id692371"></a>
|
||||
<a name="id2853708"></a>
|
||||
<a class="link" href="detailed_semantics.html#boost_optional.detailed_semantics.free_functions">Free functions</a>
|
||||
</h4>
|
||||
<p>
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Development</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="next" href="synopsis.html" title="Synopsis">
|
||||
@ -292,7 +292,7 @@
|
||||
itself which are supported by a special interface.
|
||||
</p>
|
||||
<a name="boost_optional.development.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_untitialized_optional_objects__the_operators___and___gt_"></a><h5>
|
||||
<a name="id672645"></a>
|
||||
<a name="id2836653"></a>
|
||||
<a class="link" href="development.html#boost_optional.development.the_interface.lexically_hinted_value_access_in_the_presence_of_possibly_untitialized_optional_objects__the_operators___and___gt_">Lexically-hinted
|
||||
Value Access in the presence of possibly untitialized optional objects: The
|
||||
operators * and -></a>
|
||||
@ -357,7 +357,7 @@
|
||||
incarnated by pointers.
|
||||
</p>
|
||||
<a name="boost_optional.development.the_interface.optional_lt_t_gt__as_a_model_of_optionalpointee"></a><h5>
|
||||
<a name="id672851"></a>
|
||||
<a name="id2836963"></a>
|
||||
<a class="link" href="development.html#boost_optional.development.the_interface.optional_lt_t_gt__as_a_model_of_optionalpointee">Optional<T>
|
||||
as a model of OptionalPointee</a>
|
||||
</h5>
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Examples</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="detailed_semantics.html" title="Detailed Semantics">
|
||||
<link rel="next" href="optional_references.html" title="Optional references">
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Exception Safety Guarantees</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="a_note_about_optional_bool_.html" title="A note about optional<bool>">
|
||||
<link rel="next" href="type_requirements.html" title="Type requirements">
|
||||
@ -28,7 +28,7 @@
|
||||
Guarantees</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
Because of the current implementation (see <a class="link" href="implementation_notes.html" title="Implementation Notes">Implementation
|
||||
Because of the current implementation (see <a class="link" href="../index.html#optional_implementation_notes">Implementation
|
||||
Notes</a>), all of the assignment methods:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul type="disc">
|
||||
@ -112,7 +112,7 @@
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<a name="boost_optional.exception_safety_guarantees.swap"></a><h4>
|
||||
<a name="id704586"></a>
|
||||
<a name="id2864737"></a>
|
||||
<a class="link" href="exception_safety_guarantees.html#boost_optional.exception_safety_guarantees.swap">Swap</a>
|
||||
</h4>
|
||||
<p>
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Implementation Notes</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="type_requirements.html" title="Type requirements">
|
||||
<link rel="next" href="dependencies_and_portability.html" title="Dependencies and Portability">
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>In-Place Factories</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="rebinding_semantics_for_assignment_of_optional_references.html" title="Rebinding semantics for assignment of optional references">
|
||||
<link rel="next" href="a_note_about_optional_bool_.html" title="A note about optional<bool>">
|
||||
@ -121,7 +121,7 @@
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// Wrapped object constructed in-place via a TypedInPlaceFactory.
|
||||
</span> <span class="comment">// No temporary created.
|
||||
</span> <span class="identifier">W</span> <span class="special">(</span> <span class="identifier">TypedInPlaceFactory2</span><span class="special"><</span><span class="identifier">X</span><span class="special">,</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">>(</span><span class="number">123</span><span class="special">,</span><span class="string">"hello"</span><span class="special">))</span> <span class="special">;</span>
|
||||
</span> <span class="identifier">W</span> <span class="special">(</span> <span class="identifier">TypedInPlaceFactory2</span><span class="special"><</span><span class="identifier">X</span><span class="special">,</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&</span><span class="identifier">rt</span><span class="special">(</span><span class="number">123</span><span class="special">,</span><span class="string">"hello"</span><span class="special">))</span> <span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Optional references</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="examples.html" title="Examples">
|
||||
<link rel="next" href="rebinding_semantics_for_assignment_of_optional_references.html" title="Rebinding semantics for assignment of optional references">
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Rebinding semantics for assignment of optional references</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="optional_references.html" title="Optional references">
|
||||
<link rel="next" href="in_place_factories.html" title="In-Place Factories">
|
||||
@ -70,7 +70,7 @@
|
||||
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">b</span><span class="special">==</span><span class="number">3</span><span class="special">);</span>
|
||||
</pre>
|
||||
<a name="boost_optional.rebinding_semantics_for_assignment_of_optional_references.rationale"></a><h4>
|
||||
<a name="id699431"></a>
|
||||
<a name="id2860344"></a>
|
||||
<a class="link" href="rebinding_semantics_for_assignment_of_optional_references.html#boost_optional.rebinding_semantics_for_assignment_of_optional_references.rationale">Rationale</a>
|
||||
</h4>
|
||||
<p>
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Synopsis</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="development.html" title="Development">
|
||||
<link rel="next" href="detailed_semantics.html" title="Detailed Semantics">
|
||||
|
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Type requirements</title>
|
||||
<link rel="stylesheet" href="../boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="prev" href="exception_safety_guarantees.html" title="Exception Safety Guarantees">
|
||||
<link rel="next" href="implementation_notes.html" title="Implementation Notes">
|
||||
|
BIN
doc/html/images/callouts/1.png
Normal file
After Width: | Height: | Size: 391 B |
BIN
doc/html/images/callouts/10.png
Normal file
After Width: | Height: | Size: 485 B |
BIN
doc/html/images/callouts/11.png
Normal file
After Width: | Height: | Size: 410 B |
BIN
doc/html/images/callouts/12.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
doc/html/images/callouts/13.png
Normal file
After Width: | Height: | Size: 509 B |
BIN
doc/html/images/callouts/14.png
Normal file
After Width: | Height: | Size: 499 B |
BIN
doc/html/images/callouts/15.png
Normal file
After Width: | Height: | Size: 507 B |
BIN
doc/html/images/callouts/2.png
Normal file
After Width: | Height: | Size: 446 B |
BIN
doc/html/images/callouts/3.png
Normal file
After Width: | Height: | Size: 431 B |
BIN
doc/html/images/callouts/4.png
Normal file
After Width: | Height: | Size: 441 B |
BIN
doc/html/images/callouts/5.png
Normal file
After Width: | Height: | Size: 423 B |
BIN
doc/html/images/callouts/6.png
Normal file
After Width: | Height: | Size: 431 B |
BIN
doc/html/images/callouts/7.png
Normal file
After Width: | Height: | Size: 397 B |
BIN
doc/html/images/callouts/8.png
Normal file
After Width: | Height: | Size: 434 B |
BIN
doc/html/images/callouts/9.png
Normal file
After Width: | Height: | Size: 420 B |
BIN
doc/html/images/caution.png
Executable file
After Width: | Height: | Size: 4.2 KiB |
BIN
doc/html/images/home.png
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
doc/html/images/important.png
Executable file
After Width: | Height: | Size: 4.6 KiB |
BIN
doc/html/images/next.png
Executable file
After Width: | Height: | Size: 768 B |
BIN
doc/html/images/note.png
Executable file
After Width: | Height: | Size: 4.5 KiB |
BIN
doc/html/images/prev.png
Executable file
After Width: | Height: | Size: 741 B |
BIN
doc/html/images/tip.png
Executable file
After Width: | Height: | Size: 3.8 KiB |
BIN
doc/html/images/up.png
Executable file
After Width: | Height: | Size: 766 B |
BIN
doc/html/images/warning.png
Executable file
After Width: | Height: | Size: 3.8 KiB |
@ -3,8 +3,8 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Chapter<EFBFBD>1.<2E>Boost.Optional</title>
|
||||
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||
<link rel="home" href="index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2">
|
||||
<link rel="start" href="index.html" title="Chapter<65>1.<2E>Boost.Optional">
|
||||
<link rel="next" href="boost_optional/development.html" title="Development">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
@ -27,7 +27,7 @@
|
||||
</h3></div></div>
|
||||
<div><p class="copyright">Copyright <20> 2003 -2007 Fernando Luis Cacciola Carballal</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="id663349"></a><p>
|
||||
<a name="id2826039"></a><p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
@ -164,9 +164,15 @@
|
||||
</div>
|
||||
<p>
|
||||
</p>
|
||||
<a name="optional_refassign"></a><p>
|
||||
</p>
|
||||
<a name="optional_in_place_factories"></a><p>
|
||||
</p>
|
||||
<a name="optional_implementation_notes"></a><p>
|
||||
</p>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: February 09, 2009 at 11:55:08 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: October 10, 2008 at 20:53:37 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
|
||||
|
||||
[#optional_implementation_notes]
|
||||
|
||||
[section Implementation Notes]
|
||||
|
||||
`optional<T>` is currently implemented using a custom aligned storage facility
|
||||
|
1676
doc/optional.html
Normal file
@ -331,7 +331,7 @@ factory.
|
||||
* [*Postconditions: ] `*this` is [_initialized] and its value is ['directly given]
|
||||
from the factory `f` (i.e., the value [_is not copied]).
|
||||
* [*Throws:] Whatever the `T` constructor called by the factory throws.
|
||||
* [*Notes:] See [link boost_optional.in_place_factories In-Place Factories]
|
||||
* [*Notes:] See [link optional_in_place_factories In-Place Factories]
|
||||
* [*Exception Safety:] Exceptions can only be thrown during the call to
|
||||
the `T` constructor used by the factory; in that case, this constructor has
|
||||
no effect.
|
||||
@ -385,7 +385,7 @@ __SPACE__
|
||||
* [*Postconditions: ] `*this` is initialized and it references the same
|
||||
object referenced by `rhs`.
|
||||
* [*Notes:] If `*this` was initialized, is is ['rebound] to the new object.
|
||||
See [link boost_optional.rebinding_semantics_for_assignment_of_optional_references here] for details on this behavior.
|
||||
See [link optional_refassign here] for details on this behavior.
|
||||
* [*Example:]
|
||||
``
|
||||
int a = 1 ;
|
||||
@ -444,7 +444,7 @@ __SPACE__
|
||||
references the same object referenced by `*rhs`; otherwise, `*this` is
|
||||
uninitialized (and references no object).
|
||||
* [*Notes:] If `*this` was initialized and so is *rhs, this is is ['rebound] to
|
||||
the new object. See [link boost_optional.rebinding_semantics_for_assignment_of_optional_references here] for details on this behavior.
|
||||
the new object. See [link optional_refassign here] for details on this behavior.
|
||||
* [*Example:]
|
||||
``
|
||||
int a = 1 ;
|
||||
|
@ -23,6 +23,8 @@ rather than the reference itself.
|
||||
|
||||
[endsect]
|
||||
|
||||
[#optional_refassign]
|
||||
|
||||
[section Rebinding semantics for assignment of optional references]
|
||||
|
||||
If you assign to an ['uninitialized ] `optional<T&>` the effect is to bind (for
|
||||
@ -110,6 +112,8 @@ In such scenario, you can assign the value itself directly, as in:
|
||||
|
||||
[endsect]
|
||||
|
||||
[#optional_in_place_factories]
|
||||
|
||||
[section In-Place Factories]
|
||||
|
||||
One of the typical problems with wrappers and containers is that their
|
||||
@ -201,7 +205,7 @@ A wrapper class aware of this can use it as:
|
||||
{
|
||||
// Wrapped object constructed in-place via a TypedInPlaceFactory.
|
||||
// No temporary created.
|
||||
W ( TypedInPlaceFactory2<X,int,std::string>(123,"hello")) ;
|
||||
W ( TypedInPlaceFactory2<X,int,std::string&rt(123,"hello")) ;
|
||||
}
|
||||
|
||||
The factories are divided in two groups:
|
||||
@ -284,7 +288,7 @@ instead, it won't compile).
|
||||
|
||||
[section Exception Safety Guarantees]
|
||||
|
||||
Because of the current implementation (see [link boost_optional.implementation_notes Implementation Notes]), all of the assignment methods:
|
||||
Because of the current implementation (see [link optional_implementation_notes Implementation Notes]), all of the assignment methods:
|
||||
|
||||
* `optional<T>::operator= ( optional<T> const& )`
|
||||
* `optional<T>::operator= ( T const& )`
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -9,9 +9,6 @@
|
||||
// You are welcome to contact the author at:
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
// Revisions:
|
||||
// 27 Apr 2008 (improved swap) Fernando Cacciola, Niels Dekker, Thorsten Ottosen
|
||||
//
|
||||
#ifndef BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP
|
||||
#define BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP
|
||||
|
||||
@ -22,7 +19,6 @@
|
||||
#include "boost/assert.hpp"
|
||||
#include "boost/type.hpp"
|
||||
#include "boost/type_traits/alignment_of.hpp"
|
||||
#include "boost/type_traits/has_nothrow_constructor.hpp"
|
||||
#include "boost/type_traits/type_with_alignment.hpp"
|
||||
#include "boost/type_traits/remove_reference.hpp"
|
||||
#include "boost/type_traits/is_reference.hpp"
|
||||
@ -32,7 +28,6 @@
|
||||
#include "boost/detail/reference_content.hpp"
|
||||
#include "boost/none.hpp"
|
||||
#include "boost/utility/compare_pointees.hpp"
|
||||
#include "boost/utility/in_place_factory.hpp"
|
||||
|
||||
#include "boost/optional/optional_fwd.hpp"
|
||||
|
||||
@ -521,7 +516,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
|
||||
// Creates a deep copy of another optional<T>
|
||||
// Can throw if T::T(T const&) does
|
||||
optional ( optional const& rhs ) : base( static_cast<base const&>(rhs) ) {}
|
||||
optional ( optional const& rhs ) : base(rhs) {}
|
||||
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
~optional() {}
|
||||
@ -555,7 +550,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
// (NOTE: On BCB, this operator is not actually called and left is left UNMODIFIED in case of a throw)
|
||||
optional& operator= ( optional const& rhs )
|
||||
{
|
||||
this->assign( static_cast<base const&>(rhs) ) ;
|
||||
this->assign( rhs ) ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
@ -576,14 +571,6 @@ class optional : public optional_detail::optional_base<T>
|
||||
return *this ;
|
||||
}
|
||||
|
||||
void swap( optional & arg )
|
||||
{
|
||||
// allow for Koenig lookup
|
||||
using boost::swap ;
|
||||
swap(*this, arg);
|
||||
}
|
||||
|
||||
|
||||
// Returns a reference to the value if this is initialized, otherwise,
|
||||
// the behaviour is UNDEFINED
|
||||
// No-throw
|
||||
@ -891,77 +878,44 @@ namespace optional_detail {
|
||||
#define BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
|
||||
#endif
|
||||
|
||||
template<bool use_default_constructor> struct swap_selector;
|
||||
|
||||
template<>
|
||||
struct swap_selector<true>
|
||||
// optional's swap:
|
||||
// If both are initialized, calls swap(T&, T&). If this swap throws, both will remain initialized but their values are now unspecified.
|
||||
// If only one is initialized, calls U.reset(*I), THEN I.reset().
|
||||
// If U.reset(*I) throws, both are left UNCHANGED (U is kept uinitialized and I is never reset)
|
||||
// If both are uninitialized, do nothing (no-throw)
|
||||
template<class T>
|
||||
inline
|
||||
void optional_swap ( optional<T>& x, optional<T>& y )
|
||||
{
|
||||
if ( !x && !!y )
|
||||
{
|
||||
template<class T>
|
||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
||||
{
|
||||
bool hasX = x;
|
||||
bool hasY = y;
|
||||
|
||||
if ( !hasX && !hasY )
|
||||
return;
|
||||
|
||||
if( !hasX )
|
||||
x = boost::in_place();
|
||||
else if ( !hasY )
|
||||
y = boost::in_place();
|
||||
|
||||
// GCC > 3.2 and all other compilers have the using declaration at function scope (FLC)
|
||||
x.reset(*y);
|
||||
y.reset();
|
||||
}
|
||||
else if ( !!x && !y )
|
||||
{
|
||||
y.reset(*x);
|
||||
x.reset();
|
||||
}
|
||||
else if ( !!x && !!y )
|
||||
{
|
||||
// GCC > 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 ;
|
||||
// allow for Koenig lookup
|
||||
using std::swap ;
|
||||
#endif
|
||||
swap(*x,*y);
|
||||
|
||||
if( !hasX )
|
||||
y = boost::none ;
|
||||
else if( !hasY )
|
||||
x = boost::none ;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct swap_selector<false>
|
||||
{
|
||||
template<class T>
|
||||
static void optional_swap ( optional<T>& x, optional<T>& y )
|
||||
{
|
||||
if ( !x && !!y )
|
||||
{
|
||||
x = *y;
|
||||
y = boost::none ;
|
||||
}
|
||||
else if ( !!x && !y )
|
||||
{
|
||||
y = *x ;
|
||||
x = boost::none ;
|
||||
}
|
||||
else if ( !!x && !!y )
|
||||
{
|
||||
// GCC > 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
swap(*x,*y);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace optional_detail
|
||||
|
||||
template<class T>
|
||||
struct optional_swap_should_use_default_constructor : has_nothrow_default_constructor<T> {} ;
|
||||
|
||||
template<class T> inline void swap ( optional<T>& x, optional<T>& y )
|
||||
{
|
||||
optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
|
||||
optional_detail::optional_swap(x,y);
|
||||
}
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -9,9 +9,6 @@
|
||||
// You are welcome to contact the author at:
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
// Revisions:
|
||||
// 10 May 2008 (added swap related forward declaration) Niels Dekker
|
||||
//
|
||||
#ifndef BOOST_OPTIONAL_OPTIONAL_FWD_FLC_19NOV2002_HPP
|
||||
#define BOOST_OPTIONAL_OPTIONAL_FWD_FLC_19NOV2002_HPP
|
||||
|
||||
@ -19,10 +16,6 @@ namespace boost {
|
||||
|
||||
template<class T> class optional ;
|
||||
|
||||
template<class T> void swap ( optional<T>& , optional<T>& ) ;
|
||||
|
||||
template<class T> struct optional_swap_should_use_default_constructor ;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
@ -1 +0,0 @@
|
||||
boost_module(optional DEPENDS utility)
|
1
test/.cvsignore
Normal file
@ -0,0 +1 @@
|
||||
bin
|
@ -1,16 +0,0 @@
|
||||
boost_additional_test_dependencies(optional BOOST_DEPENDS test tuple)
|
||||
|
||||
|
||||
boost_test_run(optional_test)
|
||||
boost_test_run(optional_test_tie)
|
||||
boost_test_run(optional_test_ref)
|
||||
boost_test_run(optional_test_inplace)
|
||||
boost_test_run(optional_test_io)
|
||||
boost_test_compile_fail(optional_test_fail1)
|
||||
boost_test_compile_fail(optional_test_fail3a)
|
||||
boost_test_compile_fail(optional_test_fail3b)
|
||||
boost_test_compile_fail(optional_test_ref_fail1)
|
||||
boost_test_compile_fail(optional_test_ref_fail3)
|
||||
boost_test_compile_fail(optional_test_ref_fail4)
|
||||
boost_test_compile_fail(optional_test_inplace_fail)
|
||||
boost_test_compile_fail(optional_test_inplace_fail2)
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -9,9 +9,6 @@
|
||||
// You are welcome to contact the author at:
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
// Revisions:
|
||||
// 12 May 2008 (added more swap tests)
|
||||
//
|
||||
#include<iostream>
|
||||
#include<stdexcept>
|
||||
#include<string>
|
||||
@ -19,8 +16,6 @@
|
||||
#define BOOST_ENABLE_ASSERT_HANDLER
|
||||
|
||||
#include "boost/bind/apply.hpp" // Included just to test proper interaction with boost::apply<> as reported by Daniel Wallin
|
||||
#include "boost/mpl/bool.hpp"
|
||||
#include "boost/mpl/bool_fwd.hpp" // For mpl::true_ and mpl::false_
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
@ -932,337 +927,6 @@ void test_conversions2()
|
||||
BOOST_CHECK(*get(&opt1) == static_cast<double>(f));
|
||||
}
|
||||
|
||||
|
||||
namespace optional_swap_test
|
||||
{
|
||||
class default_ctor_exception : public std::exception {} ;
|
||||
class copy_ctor_exception : public std::exception {} ;
|
||||
class assignment_exception : public std::exception {} ;
|
||||
|
||||
//
|
||||
// Base class for swap test classes. Its assignment should not be called, when swapping
|
||||
// optional<T> objects. (The default std::swap would do so.)
|
||||
//
|
||||
class base_class_with_forbidden_assignment
|
||||
{
|
||||
public:
|
||||
base_class_with_forbidden_assignment & operator=(const base_class_with_forbidden_assignment &)
|
||||
{
|
||||
BOOST_CHECK(!"The assignment should not be used while swapping!");
|
||||
throw assignment_exception();
|
||||
}
|
||||
|
||||
virtual ~base_class_with_forbidden_assignment() {}
|
||||
};
|
||||
|
||||
//
|
||||
// Class without default constructor
|
||||
//
|
||||
class class_without_default_ctor : public base_class_with_forbidden_assignment
|
||||
{
|
||||
public:
|
||||
char data;
|
||||
explicit class_without_default_ctor(char arg) : data(arg) {}
|
||||
};
|
||||
|
||||
//
|
||||
// Class whose default constructor should not be used by optional::swap!
|
||||
//
|
||||
class class_whose_default_ctor_should_not_be_used : public base_class_with_forbidden_assignment
|
||||
{
|
||||
public:
|
||||
char data;
|
||||
explicit class_whose_default_ctor_should_not_be_used(char arg) : data(arg) {}
|
||||
|
||||
class_whose_default_ctor_should_not_be_used()
|
||||
{
|
||||
BOOST_CHECK(!"This default constructor should not be used while swapping!");
|
||||
throw default_ctor_exception();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class whose default constructor should be used by optional::swap.
|
||||
// Its copy constructor should be avoided!
|
||||
//
|
||||
class class_whose_default_ctor_should_be_used : public base_class_with_forbidden_assignment
|
||||
{
|
||||
public:
|
||||
char data;
|
||||
explicit class_whose_default_ctor_should_be_used(char arg) : data(arg) { }
|
||||
|
||||
class_whose_default_ctor_should_be_used() : data('\0') { }
|
||||
|
||||
class_whose_default_ctor_should_be_used(const class_whose_default_ctor_should_be_used &)
|
||||
{
|
||||
BOOST_CHECK(!"This copy constructor should not be used while swapping!");
|
||||
throw copy_ctor_exception();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class template whose default constructor should be used by optional::swap.
|
||||
// Its copy constructor should be avoided!
|
||||
//
|
||||
template <class T>
|
||||
class template_whose_default_ctor_should_be_used : public base_class_with_forbidden_assignment
|
||||
{
|
||||
public:
|
||||
T data;
|
||||
explicit template_whose_default_ctor_should_be_used(T arg) : data(arg) { }
|
||||
|
||||
template_whose_default_ctor_should_be_used() : data('\0') { }
|
||||
|
||||
template_whose_default_ctor_should_be_used(const template_whose_default_ctor_should_be_used &)
|
||||
{
|
||||
BOOST_CHECK(!"This copy constructor should not be used while swapping!");
|
||||
throw copy_ctor_exception();
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class whose explicit constructor should be used by optional::swap.
|
||||
// Its other constructors should be avoided!
|
||||
//
|
||||
class class_whose_explicit_ctor_should_be_used : public base_class_with_forbidden_assignment
|
||||
{
|
||||
public:
|
||||
char data;
|
||||
explicit class_whose_explicit_ctor_should_be_used(char arg) : data(arg) { }
|
||||
|
||||
class_whose_explicit_ctor_should_be_used()
|
||||
{
|
||||
BOOST_CHECK(!"This default constructor should not be used while swapping!");
|
||||
throw default_ctor_exception();
|
||||
}
|
||||
|
||||
class_whose_explicit_ctor_should_be_used(const class_whose_explicit_ctor_should_be_used &)
|
||||
{
|
||||
BOOST_CHECK(!"This copy constructor should not be used while swapping!");
|
||||
throw copy_ctor_exception();
|
||||
}
|
||||
};
|
||||
|
||||
void swap(class_whose_default_ctor_should_not_be_used & lhs, class_whose_default_ctor_should_not_be_used & rhs)
|
||||
{
|
||||
std::swap(lhs.data, rhs.data);
|
||||
}
|
||||
|
||||
void swap(class_whose_default_ctor_should_be_used & lhs, class_whose_default_ctor_should_be_used & rhs)
|
||||
{
|
||||
std::swap(lhs.data, rhs.data);
|
||||
}
|
||||
|
||||
void swap(class_without_default_ctor & lhs, class_without_default_ctor & rhs)
|
||||
{
|
||||
std::swap(lhs.data, rhs.data);
|
||||
}
|
||||
|
||||
void swap(class_whose_explicit_ctor_should_be_used & lhs, class_whose_explicit_ctor_should_be_used & rhs)
|
||||
{
|
||||
std::swap(lhs.data, rhs.data);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void swap(template_whose_default_ctor_should_be_used<T> & lhs, template_whose_default_ctor_should_be_used<T> & rhs)
|
||||
{
|
||||
std::swap(lhs.data, rhs.data);
|
||||
}
|
||||
|
||||
//
|
||||
// optional<T>::swap should be customized when neither the copy constructor
|
||||
// nor the default constructor of T are supposed to be used when swapping, e.g.,
|
||||
// for the following type T = class_whose_explicit_ctor_should_be_used.
|
||||
//
|
||||
void swap(boost::optional<class_whose_explicit_ctor_should_be_used> & x, boost::optional<class_whose_explicit_ctor_should_be_used> & y)
|
||||
{
|
||||
bool hasX = x;
|
||||
bool hasY = y;
|
||||
|
||||
if ( !hasX && !hasY )
|
||||
return;
|
||||
|
||||
if( !hasX )
|
||||
x = boost::in_place('\0');
|
||||
else if ( !hasY )
|
||||
y = boost::in_place('\0');
|
||||
|
||||
optional_swap_test::swap(*x,*y);
|
||||
|
||||
if( !hasX )
|
||||
y = boost::none ;
|
||||
else if( !hasY )
|
||||
x = boost::none ;
|
||||
}
|
||||
|
||||
|
||||
} // End of namespace optional_swap_test.
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
//
|
||||
// Compile time tweaking on whether or not swap should use the default constructor:
|
||||
//
|
||||
|
||||
template <> struct optional_swap_should_use_default_constructor<
|
||||
optional_swap_test::class_whose_default_ctor_should_be_used> : mpl::true_ {} ;
|
||||
|
||||
template <> struct optional_swap_should_use_default_constructor<
|
||||
optional_swap_test::class_whose_default_ctor_should_not_be_used> : mpl::false_ {} ;
|
||||
|
||||
template <class T> struct optional_swap_should_use_default_constructor<
|
||||
optional_swap_test::template_whose_default_ctor_should_be_used<T> > : mpl::true_ {} ;
|
||||
|
||||
|
||||
//
|
||||
// Specialization of boost::swap:
|
||||
//
|
||||
template <>
|
||||
void swap(optional<optional_swap_test::class_whose_explicit_ctor_should_be_used> & x, optional<optional_swap_test::class_whose_explicit_ctor_should_be_used> & y)
|
||||
{
|
||||
optional_swap_test::swap(x, y);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
namespace std {
|
||||
|
||||
//
|
||||
// Specializations of std::swap:
|
||||
//
|
||||
|
||||
template <>
|
||||
void swap(optional_swap_test::class_whose_default_ctor_should_be_used & x, optional_swap_test::class_whose_default_ctor_should_be_used & y)
|
||||
{
|
||||
optional_swap_test::swap(x, y);
|
||||
}
|
||||
|
||||
template <>
|
||||
void swap(optional_swap_test::class_whose_default_ctor_should_not_be_used & x, optional_swap_test::class_whose_default_ctor_should_not_be_used & y)
|
||||
{
|
||||
optional_swap_test::swap(x, y);
|
||||
}
|
||||
|
||||
template <>
|
||||
void swap(optional_swap_test::class_without_default_ctor & x, optional_swap_test::class_without_default_ctor & y)
|
||||
{
|
||||
optional_swap_test::swap(x, y);
|
||||
}
|
||||
|
||||
template <>
|
||||
void swap(optional_swap_test::class_whose_explicit_ctor_should_be_used & x, optional_swap_test::class_whose_explicit_ctor_should_be_used & y)
|
||||
{
|
||||
optional_swap_test::swap(x, y);
|
||||
}
|
||||
|
||||
} // namespace std
|
||||
|
||||
|
||||
//
|
||||
// Tests whether the swap function works properly for optional<T>.
|
||||
// Assumes that T has one data member, of type char.
|
||||
// Returns true iff the test is passed.
|
||||
//
|
||||
template <class T>
|
||||
bool test_swap_function( T const* )
|
||||
{
|
||||
const boost::unit_test::counter_t counter_before_test = boost::minimal_test::errors_counter();
|
||||
try
|
||||
{
|
||||
optional<T> obj1;
|
||||
optional<T> obj2('a');
|
||||
|
||||
// Self-swap should not have any effect.
|
||||
swap(obj1, obj1);
|
||||
swap(obj2, obj2);
|
||||
BOOST_CHECK(!obj1);
|
||||
BOOST_CHECK(!!obj2 && obj2->data == 'a');
|
||||
|
||||
// Call non-member swap.
|
||||
swap(obj1, obj2);
|
||||
|
||||
// Test if obj1 and obj2 are really swapped.
|
||||
BOOST_CHECK(!!obj1 && obj1->data == 'a');
|
||||
BOOST_CHECK(!obj2);
|
||||
|
||||
// Call non-member swap one more time.
|
||||
swap(obj1, obj2);
|
||||
|
||||
// Test if obj1 and obj2 are swapped back.
|
||||
BOOST_CHECK(!obj1);
|
||||
BOOST_CHECK(!!obj2 && obj2->data == 'a');
|
||||
}
|
||||
catch(const std::exception &)
|
||||
{
|
||||
// The swap function should not throw, for our test cases.
|
||||
return false ;
|
||||
}
|
||||
return boost::minimal_test::errors_counter() == counter_before_test ;
|
||||
}
|
||||
|
||||
//
|
||||
// Tests whether the optional<T>::swap member function works properly.
|
||||
// Assumes that T has one data member, of type char.
|
||||
// Returns true iff the test is passed.
|
||||
//
|
||||
template <class T>
|
||||
bool test_swap_member_function( T const* )
|
||||
{
|
||||
const boost::unit_test::counter_t counter_before_test = boost::minimal_test::errors_counter();
|
||||
try
|
||||
{
|
||||
optional<T> obj1;
|
||||
optional<T> obj2('a');
|
||||
|
||||
// Self-swap should not have any effect.
|
||||
obj1.swap(obj1);
|
||||
obj2.swap(obj2);
|
||||
BOOST_CHECK(!obj1);
|
||||
BOOST_CHECK(!!obj2 && obj2->data == 'a');
|
||||
|
||||
// Call member swap.
|
||||
obj1.swap(obj2);
|
||||
|
||||
// Test if obj1 and obj2 are really swapped.
|
||||
BOOST_CHECK(!!obj1 && obj1->data == 'a');
|
||||
BOOST_CHECK(!obj2);
|
||||
|
||||
// Call member swap one more time.
|
||||
obj1.swap(obj2);
|
||||
|
||||
// Test if obj1 and obj2 are swapped back.
|
||||
BOOST_CHECK(!obj1);
|
||||
BOOST_CHECK(!!obj2 && obj2->data == 'a');
|
||||
}
|
||||
catch(const std::exception &)
|
||||
{
|
||||
// The optional<T>::swap member function should not throw, for our test cases.
|
||||
return false ;
|
||||
}
|
||||
return boost::minimal_test::errors_counter() == counter_before_test ;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Tests compile time tweaking of swap, by means of
|
||||
// optional_swap_should_use_default_constructor.
|
||||
//
|
||||
void test_swap_tweaking()
|
||||
{
|
||||
BOOST_CHECK( test_swap_function( ARG(optional_swap_test::class_without_default_ctor) ) );
|
||||
BOOST_CHECK( test_swap_function( ARG(optional_swap_test::class_whose_default_ctor_should_be_used) ) );
|
||||
BOOST_CHECK( test_swap_function( ARG(optional_swap_test::class_whose_default_ctor_should_not_be_used) ) );
|
||||
BOOST_CHECK( test_swap_function( ARG(optional_swap_test::class_whose_explicit_ctor_should_be_used) ) );
|
||||
BOOST_CHECK( test_swap_function( ARG(optional_swap_test::template_whose_default_ctor_should_be_used<char>) ) );
|
||||
BOOST_CHECK( test_swap_member_function( ARG(optional_swap_test::class_without_default_ctor) ) );
|
||||
BOOST_CHECK( test_swap_member_function( ARG(optional_swap_test::class_whose_default_ctor_should_be_used) ) );
|
||||
BOOST_CHECK( test_swap_member_function( ARG(optional_swap_test::class_whose_default_ctor_should_not_be_used) ) );
|
||||
BOOST_CHECK( test_swap_member_function( ARG(optional_swap_test::class_whose_explicit_ctor_should_be_used) ) );
|
||||
BOOST_CHECK( test_swap_member_function( ARG(optional_swap_test::template_whose_default_ctor_should_be_used<char>) ) );
|
||||
}
|
||||
|
||||
int test_main( int, char* [] )
|
||||
{
|
||||
try
|
||||
@ -1272,7 +936,6 @@ int test_main( int, char* [] )
|
||||
test_no_implicit_conversions();
|
||||
test_conversions1();
|
||||
test_conversions2();
|
||||
test_swap_tweaking();
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
|
@ -342,14 +342,14 @@ void test_binding()
|
||||
int i = 0 ;
|
||||
optional<int&> ori1 = i ;
|
||||
BOOST_CHECK( &(*ori1) == &i ) ;
|
||||
|
||||
|
||||
optional<int&> ori2(i) ;
|
||||
BOOST_CHECK( &(*ori2) == &i ) ;
|
||||
|
||||
|
||||
int const ci = 0 ;
|
||||
optional<int const&> orci1 = ci ;
|
||||
BOOST_CHECK( &(*orci1) == &ci ) ;
|
||||
|
||||
|
||||
optional<int const&> orci2(ci) ;
|
||||
BOOST_CHECK( &(*orci2) == &ci ) ;
|
||||
}
|
||||
@ -360,7 +360,7 @@ int test_main( int, char* [] )
|
||||
{
|
||||
test_with_class_type();
|
||||
test_with_builtin_types();
|
||||
test_binding();
|
||||
test_binding();
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
|
23
test/optional_test_ref_fail2.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
#include "boost/optional.hpp"
|
||||
|
||||
//
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
//
|
||||
void optional_reference__test_no_ptr_access()
|
||||
{
|
||||
boost::optional<int&> opt ;
|
||||
opt.get_ptr();
|
||||
}
|
||||
|
||||
|