From f092580a0ed0367aca6c492d74601f53a82dac41 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 9 Feb 2016 19:06:13 +0200 Subject: Implement ==, != operators for optional class template --- butl/optional | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'butl/optional') 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 + inline auto + operator== (const optional& x, const optional& y) -> decltype (*x == *y) + { + return static_cast (x) == static_cast (y) && (!x || *x == *y); + } + + template + inline auto + operator!= (const optional& x, const optional& y) -> decltype (x == y) + { + return !(x == y); + } } #endif // BUTL_OPTIONAL -- cgit v1.1