Boost logo

Boost :

From: Jorge Lodos (lodos_at_[hidden])
Date: 2006-04-18 15:58:57


 
> >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.

Yes, that's why I said the first solution (the one you did not include) was
not satisfactory.

> Thus, defining an operator == for any is counter-intuitive,
> and doesn't work properly anyway. The proposed solution below:

Why is it counter-intuitive? I expect that 2 anys are equal if the following
conditions are both true:
1. The holded objects have operator== defined
2. The holded objects are equal.

> 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.

Only if the operator== is not defined for holded object. I would not say the
solution does not make sense, but I don't think this is what is needed. Note
this is not my solution. Allthough I like the trick proposed there and I'm
sure it can be used in other more suitable places, the credit is not mine.

> 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

Why not? As long as:
1. The operator has meaning for holded objects.
2. The operation can be performed between holded objects
3. The code won't compile if some not defined (by holded objects) operator
is used.
I'm not talking here about feasibility, but as the "whole basic idea". Sorry
this causes you irritation.

> 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#.
>
What I want is equality.

> Sebastian Redl
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

Jorge Lodos


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