Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-04-17 20:17:44


Jorge Lodos wrote:

>Hi
>It would be nice if operator== could be added to boost::any.
>
That does not make sense. The purpose of any is to be a generic holder
for ANY type, which includes those that are not equality comparable.
Thus, defining an operator == for any is counter-intuitive, and doesn't
work properly anyway. The proposed solution below:

>
>namespace equality
>{
> template<typename Type>
> bool operator==(const Type &lhs, const Type &rhs)
> {
> return &lhs == &rhs;
> }
>}
>
>
does not make sense because every any allocates its own inner object. In
other words, the identity equality check of the held object is
effectively an identity equality check of the any object itself.
But aside from the implementation and semantic problem, the whole basic
idea irritates me. What makes equality check special? Why not implement
+, >, and all the other operators for any too? Let's never forget that
equality is about value equality, not about identity. If you want
identity, you should compare the addresses in the first place. The
mixing of these two concepts is one of the things I dislike about Java
and particularly C#.

Sebastian Redl


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk