mirror of
https://github.com/boostorg/outcome.git
synced 2026-01-19 16:32:13 +00:00
62 lines
3.5 KiB
HTML
62 lines
3.5 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<title>Result returning constructors - Boost.Outcome documentation</title>
|
|
<link rel="stylesheet" href="../css/boost.css" type="text/css">
|
|
<meta name="generator" content="Hugo 0.52 with Boostdoc theme">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
|
|
|
|
<link rel="icon" href="../images/favicon.ico" type="image/ico"/>
|
|
<body><div id="boost-common-heading-doc" style="background: #574D74 url('../images/header-bg.png') repeat-x top left;">
|
|
<div class="heading-inner" style="background: url('../images/header-fg.png') no-repeat top left;">
|
|
<div class="heading-placard"></div>
|
|
|
|
<h1 class="heading-title">
|
|
<a href="../">
|
|
<img src="../images/space.png" alt="Boost C++ Libraries" class="heading-logo" />
|
|
<span class="heading-boost">Boost</span>
|
|
<span class="heading-cpplibraries">C++ Libraries</span>
|
|
</a>
|
|
</h1>
|
|
|
|
<p class="heading-quote">
|
|
<q>...one of the most highly
|
|
regarded and expertly designed C++ library projects in the
|
|
world.</q> <span class="heading-attribution">— <a href=
|
|
"http://www.gotw.ca/" class="external">Herb Sutter</a> and <a href=
|
|
"http://en.wikipedia.org/wiki/Andrei_Alexandrescu" class="external">Andrei
|
|
Alexandrescu</a>, <a href=
|
|
"http://safari.awprofessional.com/?XmlId=0321113586" class="external">C++
|
|
Coding Standards</a></span></p>
|
|
</div>
|
|
</div>
|
|
<div id="boost-common-heading-doc-spacer"></div><div class="spirit-nav">
|
|
<a accesskey="p" href="../tutorial/payload/copy_file3.html"><img src="../images/prev.png" alt="Prev"></a>
|
|
<a accesskey="u" href="../tutorial.html"><img src="../images/up.png" alt="Up"></a>
|
|
<a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../tutorial/constructors/two-phase-init.html"><img src="../images/next.png" alt="Next"></a></div><div id="content">
|
|
|
|
<div class="titlepage"><div><div><h1 style="clear: both">Result returning constructors</h1></div></div></div>
|
|
<p>An oft asked question during conference talks on Expected/Outcome is how to
|
|
exclusively use <code>result</code> to implement constructor failure. This is asked because
|
|
whilst almost every member function in a class can return a <code>result</code>, constructors
|
|
do not return values and thus cannot return a <code>result</code>. The implication is
|
|
that one cannot avoid throwing C++ exceptions to abort a construction.</p>
|
|
|
|
<p>As with most things in C++, one can achieve zero-exception-throw object
|
|
construction using a lot of
|
|
extra typing of boilerplate, and a little bit of simple C++ metaprogramming. This section
|
|
shows you how to implement these for those who are absolutely adverse to ever throwing an exception,
|
|
or cannot because C++ exceptions have been globally disabled.</p>
|
|
|
|
<p>The technique described here is not suitable for non-copyable and non-movable
|
|
types. There is also an assumption that moving your type is cheap.</p>
|
|
|
|
|
|
|
|
</div><p><small>Last revised: December 13, 2017 at 09:28:03 UTC</small></p>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="../tutorial/payload/copy_file3.html"><img src="../images/prev.png" alt="Prev"></a>
|
|
<a accesskey="u" href="../tutorial.html"><img src="../images/up.png" alt="Up"></a>
|
|
<a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../tutorial/constructors/two-phase-init.html"><img src="../images/next.png" alt="Next"></a></div></body>
|
|
</html>
|