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>Constexpr domain source - 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 8<link rel="icon" href="../../images/favicon.ico" type="image/ico"/> 9<body><div class="spirit-nav"> 10<a accesskey="p" href="../../experimental/worked-example/message.html"><img src="../../images/prev.png" alt="Prev"></a> 11 <a accesskey="u" href="../../experimental/worked-example.html"><img src="../../images/up.png" alt="Up"></a> 12 <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../experimental/worked-example/implicit_conversion.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content"> 13 <div class="titlepage"><div><div><h1 style="clear: both">Constexpr domain source</h1></div></div></div> 14 <p>Back in <a href="../../experimental/worked-example/constructor.html">The constructor</a>, we 15declared but did not implement a <code>.get()</code> function which returns a constexpr static 16instance of the domain. We implement this now:</p> 17 18<div class="code-snippet"><div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="c1">// 100% constexpr instantiation 19</span><span class="c1"></span><span class="k">constexpr</span> <span class="n">_file_io_error_domain</span> <span class="n">file_io_error_domain</span><span class="p">;</span> 20<span class="kr">inline</span> <span class="k">constexpr</span> <span class="k">const</span> <span class="n">_file_io_error_domain</span> <span class="o">&</span><span class="n">_file_io_error_domain</span><span class="o">::</span><span class="n">get</span><span class="p">()</span> 21<span class="p">{</span> 22 <span class="k">return</span> <span class="n">file_io_error_domain</span><span class="p">;</span> 23<span class="p">}</span> 24</code></pre></div><a href="https://github.com/boostorg/outcome/tree/master/doc/src/snippets/experimental_status_code.cpp#L142" class="code-snippet-url" target="_blank">View this code on Github</a></div> 25 26 27<p>As this is 100% constexpr, it can be (and is under optimisation) implemented entirely 28in the mind of the compiler with no run time representation.</p> 29 30 31 </div><p><small>Last revised: January 26, 2019 at 23:38:56 UTC</small></p> 32<hr> 33<div class="spirit-nav"> 34<a accesskey="p" href="../../experimental/worked-example/message.html"><img src="../../images/prev.png" alt="Prev"></a> 35 <a accesskey="u" href="../../experimental/worked-example.html"><img src="../../images/up.png" alt="Up"></a> 36 <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../experimental/worked-example/implicit_conversion.html"><img src="../../images/next.png" alt="Next"></a></div></body> 37</html> 38