Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2007-10-08 03:30:00


Marco Costalba wrote:

>> It has the right semantics and is very idiomatic. This is how
>> Boost.Function does it. Only in this case, we can have many mappings
>> instead of just one.
>>
> I would prefer 'add' or 'assign' here because 'overload' is a kind of
> a container while fooX are single functions.
>
> My intuitive idea of operator=() is that at the end what is at the
> left is == of what is at the right, in other words:
>
> std::string a;
> a = "apple"; // now I would think 'a' is an apple
> a = "blueberry"; // now 'a' is *no more* an apple, is a blueberry
>
> assert(a=="apple"); // ??? strange last assignement was a bluebarry here!

Assignment can be lossy, you know. Here's a sample:

    int x;
    x = 0.0001;
    x == 0.0001; // ??? huh

That "overloads" is a container is an implementation detail. Or
how about:

     std::string a;
     a = 'x';
     a == 'x'; // oops can't compare char and string

at any rate, It *is* possible to follow the semantics of Boost.Function:
http://boost.org/doc/html/function/tutorial.html#id1187293

     int compute_with_X(X*, int);

     f = &X::foo;
     assert(f == &X::foo);
     assert(&compute_with_X != f);

by using Boost Function itself to do the comparison.

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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