aboutsummaryrefslogtreecommitdiff
path: root/butl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-02-09 19:06:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-02-10 00:41:33 +0200
commitf092580a0ed0367aca6c492d74601f53a82dac41 (patch)
treede3dcfac7a226c33f608037eb763e6acfa0c2fd9 /butl
parenta24c33aa9932435f2d8f9bdce6acaabfc5e81176 (diff)
Implement ==, != operators for optional class template
Diffstat (limited to 'butl')
-rw-r--r--butl/optional14
1 files changed, 14 insertions, 0 deletions
diff --git a/butl/optional b/butl/optional
index 308302e..00c204a 100644
--- a/butl/optional
+++ b/butl/optional
@@ -40,6 +40,20 @@ namespace butl
T value_;
bool null_;
};
+
+ template <typename T>
+ inline auto
+ operator== (const optional<T>& x, const optional<T>& y) -> decltype (*x == *y)
+ {
+ return static_cast<bool> (x) == static_cast<bool> (y) && (!x || *x == *y);
+ }
+
+ template <typename T>
+ inline auto
+ operator!= (const optional<T>& x, const optional<T>& y) -> decltype (x == y)
+ {
+ return !(x == y);
+ }
}
#endif // BUTL_OPTIONAL