aboutsummaryrefslogtreecommitdiff
path: root/lib/util.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-14 23:32:16 +0900
committerGitHub <noreply@github.com>2018-12-14 23:32:16 +0900
commitfcc8d2ca615fce6e42bf1cf6585d60f94a2db926 (patch)
treeb0dd17b632a5c5775f2221fd0b53b21a8c02ce58 /lib/util.h
parent50571a92b4e9f634c4daf546222fa082120db6c7 (diff)
parent12a0b95fdcfea15cd0ef313aec8868656629b986 (diff)
downloadlibquotient-fcc8d2ca615fce6e42bf1cf6585d60f94a2db926.tar.gz
libquotient-fcc8d2ca615fce6e42bf1cf6585d60f94a2db926.zip
Merge pull request #263 from QMatrixClient/kitsune-lazy-loading
Lazy loading members
Diffstat (limited to 'lib/util.h')
-rw-r--r--lib/util.h16
1 files changed, 16 insertions, 0 deletions
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 <typename T1>
+ auto merge(const Omittable<T1>& other)
+ -> std::enable_if_t<std::is_convertible<T1, 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(); }