Null object: Difference between revisions

→‎{{header|C++}}: Prefer C++17's std::optional over boost::optional since most modern compilers fully support C++17, but keep boost::optional as a blurb
(→‎{{header|C++}}: Prefer C++17's std::optional over boost::optional since most modern compilers fully support C++17, but keep boost::optional as a blurb)
Line 389:
}</lang>
 
booststd::optional is available since C++17 (or Boost's boost::optional via boost/optional.hpp for earlier standards) for cases where the programmer wishes to pass by value, but still support a null value.
 
<lang cpp>
#include <boost/optional.hpp>
#include <iostream>
#include <boost/optional.hpp>
 
booststd::optional<int> maybeInt()
 
int main()
{
booststd::optional<int> maybe = maybeInt();
 
if(!maybe)
Anonymous user