From 110de28be0b09ed8d2b445769a59ea66c07c83d7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2015 15:34:27 +0200 Subject: Add nullopt_t/nullopt to optional --- butl/optional | 6 ++++++ 1 file changed, 6 insertions(+) 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 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_;} -- cgit v1.1