constructors.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. <title>Result returning constructors - Boost.Outcome documentation</title>
  4. <link rel="stylesheet" href="../../css/boost.css" type="text/css">
  5. <meta name="generator" content="Hugo 0.52 with Boostdoc theme">
  6. <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
  7. <link rel="icon" href="../../images/favicon.ico" type="image/ico"/>
  8. <body><div class="spirit-nav">
  9. <a accesskey="p" href="../../tutorial/advanced/payload/copy_file3.html"><img src="../../images/prev.png" alt="Prev"></a>
  10. <a accesskey="u" href="../../tutorial/advanced.html"><img src="../../images/up.png" alt="Up"></a>
  11. <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../tutorial/advanced/constructors/two-phase-init.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content">
  12. <div class="titlepage"><div><div><h1 style="clear: both">Result returning constructors</h1></div></div></div>
  13. <p>An oft-asked question during conference talks on Expected/Outcome is how to
  14. exclusively use <code>result</code> to implement constructor failure. This is asked because
  15. whilst almost every member function in a class can return a <code>result</code>, constructors
  16. do not return values and thus cannot return a <code>result</code>. The implication is
  17. that one cannot avoid throwing C++ exceptions to abort a construction.</p>
  18. <p>As with most things in C++, one can achieve zero-exception-throw object
  19. construction using a lot of
  20. extra typing of boilerplate, and a little bit of simple C++ metaprogramming. This section
  21. shows you how to implement these for those who are absolutely adverse to ever throwing an exception,
  22. or cannot because C++ exceptions have been globally disabled.</p>
  23. <p>The technique described here is not suitable for non-copyable and non-movable
  24. types. There is also an assumption that moving your type is cheap.</p>
  25. </div><p><small>Last revised: June 24, 2019 at 21:48:18 &#43;0100</small></p>
  26. <hr>
  27. <div class="spirit-nav">
  28. <a accesskey="p" href="../../tutorial/advanced/payload/copy_file3.html"><img src="../../images/prev.png" alt="Prev"></a>
  29. <a accesskey="u" href="../../tutorial/advanced.html"><img src="../../images/up.png" alt="Up"></a>
  30. <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../tutorial/advanced/constructors/two-phase-init.html"><img src="../../images/next.png" alt="Next"></a></div></body>
  31. </html>