From 4a252aa465c7a36268e8014674800e6d98a449e9 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 8 Dec 2018 22:39:38 +0900 Subject: Omittable<>::merge<> --- lib/util.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/util.h') diff --git a/lib/util.h b/lib/util.h index 0066c03d..9c9a37ba 100644 --- a/lib/util.h +++ b/lib/util.h @@ -118,6 +118,22 @@ namespace QMatrixClient _omitted = false; return _value; } + /// Merge the value from another Omittable + /// \return true if \p other is not omitted and the value of + /// the current Omittable was different (or omitted); + /// in other words, if the current Omittable has changed; + /// false otherwise + template + auto merge(const Omittable& other) + -> std::enable_if_t::value, bool> + { + if (other.omitted() || + (!_omitted && _value == other.value())) + return false; + _omitted = false; + _value = other.value(); + return true; + } value_type&& release() { _omitted = true; return std::move(_value); } operator value_type&() & { return editValue(); } -- cgit v1.2.3