|
Boost : |
Subject: [boost] Boost Optional
From: Rafael Justo (cadastros_at_[hidden])
Date: 2012-03-28 15:55:08
Hello! This is my first post in this list. =)
I was looking today at Boost Optional (great work!).
And I was wondering how could I do something like the bellow code.
--------------------------------
#include <boost/optional.hpp>
class Test {};
boost::optional<Test> get()
{
return boost::optional<Test>();
}
int main()
{
if (get() == true) {
// OK
} else if (get() == false) {
// ERROR
}
return 0;
}
--------------------------------
But there's no "operator==" with bool in optional.hpp,
so the above code don't compile (i have checked version 1.49).
Is it possible to add the patch described bellow in optional.hpp
to solve this problem?
--------------------------------
--- boost_1_49_0/boost/optional/optional.hpp 2010-12-18
19:29:39.000000000 -0200
+++ boost_1_49_0_new/boost/optional/optional.hpp 2012-03-28
16:03:53.417578997 -0300
@@ -616,6 +616,11 @@
return *this ;
}
+ bool operator== (const bool condition)
+ {
+ return ((*this && condition) || (!*this && !condition));
+ }
+
void swap( optional & arg )
{
// allow for Koenig lookup
--------------------------------
Best regards,
Rafael Justo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk