From 5ea115d6eb0b60dfd0c2be5fbe5e69615b133238 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 24 Nov 2018 11:58:43 +0900 Subject: Omittable: better editability; drop implicit cast to bool --- lib/util.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lib/util.h') diff --git a/lib/util.h b/lib/util.h index 1028e059..722a7e3d 100644 --- a/lib/util.h +++ b/lib/util.h @@ -108,15 +108,23 @@ namespace QMatrixClient } bool omitted() const { return _omitted; } - const value_type& value() const { Q_ASSERT(!_omitted); return _value; } - value_type& value() { Q_ASSERT(!_omitted); return _value; } + const value_type& value() const + { + Q_ASSERT(!_omitted); + return _value; + } + value_type& editValue() + { + _omitted = false; + return _value; + } value_type&& release() { _omitted = true; return std::move(_value); } - operator bool() const { return !omitted(); } - const value_type* operator->() const { return &_value; } - value_type* operator->() { return &_value; } - const value_type& operator*() const { return _value; } - value_type& operator*() { return _value; } + operator value_type&() & { return editValue(); } + const value_type* operator->() const & { return &value(); } + value_type* operator->() & { return &editValue(); } + const value_type& operator*() const & { return value(); } + value_type& operator*() & { return editValue(); } private: T _value; -- cgit v1.2.3