aboutsummaryrefslogtreecommitdiff
path: root/butl/optional
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-17 15:34:27 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-17 15:34:27 +0200
commit110de28be0b09ed8d2b445769a59ea66c07c83d7 (patch)
tree8612416bb677ac24932d04418e1109ceb56c7e22 /butl/optional
parent6ea179f5c53c40c83d3cc023ad1e3ea36efaeed5 (diff)
Add nullopt_t/nullopt to optional
Diffstat (limited to 'butl/optional')
-rw-r--r--butl/optional6
1 files changed, 6 insertions, 0 deletions
diff --git a/butl/optional b/butl/optional
index fc34b33..a8f810e 100644
--- a/butl/optional
+++ b/butl/optional
@@ -9,6 +9,9 @@ namespace butl
{
// Simple optional class template while waiting for std::optional.
//
+ struct nullopt_t {constexpr nullopt_t (int) {}};
+ constexpr nullopt_t nullopt = 1;
+
template <typename T>
class optional
{
@@ -16,7 +19,10 @@ namespace butl
typedef T value_type;
optional (): null_ (true) {}
+ optional (nullopt_t): null_ (true) {}
optional (const T& v): value_ (v), null_ (false) {}
+
+ optional& operator= (nullopt_t) {value_ = T (); null_ = true; return *this;}
optional& operator= (const T& v) {value_ = v; null_ = false; return *this;}
T& value () {return value_;}