 <p>The semantics of a value being missing are exactly why <a href="http://en.cppreference.com/w/cpp/utility/optional" rel="nofollow"><code>std::optional</code></a> was introduced to the C++ language specification.</p> <pre><code>std::optional&lt;unsigned int&gt; value; // by default, the value is missing if(value) { // executed if the value is present, it is not } else { // this code is executed } value = 1; if(value) { // This code would now be executed std::cout &lt;&lt; "the value: " &lt;&lt; *value &lt;&lt; std::endl; } </code></pre> <p>This requires a change in thinking regarding the meaning of the variable, but it forces you to think at all times regarding whether or not the variable would be present.</p> <p>So for example, if you had your own class type <code>MyClass</code> and you wanted to retain a, potentially missing, instance of it, you would do so as follows:</p> <pre><code>std::optional&lt;MyClass&gt; obj; // Initially missing obj = MyClass(); // Assigns a newly-created instance of MyClass obj-&gt;foo(); // Calls the 'MyClass::foo' method obj.reset(); // clears the 'obj' optional </code></pre>