[optional] reduce need for operator ==

Hi! currently boost::optional<Type> requires an operator == for Type. If I only want to check if the optional is present or not, then this is not necessary. e.g. struct Foo {int i;}; boost::optional<Foo> foo; if (foo == boost::none) ... is it possible to change this? for example by template<class T> inline bool operator == ( optional<T> const& x, none_t ) { return !x; } -Jochen

On 19 July 2012 10:42, Jochen Wilhelmy <jochen.wilhelmy@googlemail.com> wrote:
Hi!
currently boost::optional<Type> requires an operator == for Type. If I only want to check if the optional is present or not, then this is not necessary. e.g. struct Foo {int i;}; boost::optional<Foo> foo; if (foo == boost::none) ...
is it possible to change this? for example by
template<class T> inline bool operator == ( optional<T> const& x, none_t ) { return !x; }
Sounds like a good idea to me. -- Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404

On 19-07-2012 20:59, Nevin Liber wrote:
On 19 July 2012 10:42, Jochen Wilhelmy <jochen.wilhelmy@googlemail.com> wrote:
Hi!
currently boost::optional<Type> requires an operator == for Type. If I only want to check if the optional is present or not, then this is not necessary. e.g. struct Foo {int i;}; boost::optional<Foo> foo; if (foo == boost::none) ...
is it possible to change this? for example by
template<class T> inline bool operator == ( optional<T> const& x, none_t ) { return !x; }
Sounds like a good idea to me.
+1 -Thorsten
participants (3)
-
Jochen Wilhelmy
-
Nevin Liber
-
Thorsten Ottosen