Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2006-04-24 13:52:38


Jorge Lodos wrote:
> Hi
> The following is a partial solution for boost::any operations, including
> operator==.
> [ skiped ]
> This is different from any_cast in that it returns a reference, instead of a
> copy. Note also that this will never be used implicitely, you have to call
> operator ValueType&() explicitely.

any_cast already supports reference types.

> Operations with values can be added as:
>
> template <typename ValueType>
> bool operator==(const ValueType& rhs)
> {
> return rhs == this->operator ValueType&();
> }
>
> Or
>
> template <typename ValueType>
> any& operator+=(const ValueType& rhs)
> {
> this->operator ValueType&() += rhs;
> return *this;
> }

There is another way of doing this:

typedef mpl::vector< less<typeof(_1 == _2)>
                   , plus<typeof(_1 + _2)>
> ops;
any<ops> a = 0;
any<ops> b = a + a;

assert( b == a );

I have a partial solution but I want better multimethods.

-- 
Alexander Nasonov
Project Manager
http://www.akmosoft.com

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