From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-10-08 01:14:47
On 10/8/07, Joel de Guzman <joel_at_[hidden]> wrote:
> Marco Costalba wrote:
> > On 10/7/07, Miles Bader <miles_at_[hidden]> wrote:
> >> "Marco Costalba" <mcostalba_at_[hidden]> writes:
> >>> boost::overload<Signatures> f;
> >>> // assign functions in any order
> >>> f.add_overload(foo4);
> >> Given that the entire point is to hold overloads, isn't "add_overload" a
> >> bit redundant? Why not just "add"?
> > Yes I agree, also because 'overload' is already the name of the struct
> > so perhaps add_function() would be better but also functors can be
> > added so....perhaps just add() is the best, util now ;-)
> "add" looks good, until you "add" something outside the overload set.
> You can't. The right word is "assign". But then what's wrong with
> f = &foo4;
> f = &foo2;
> f = &foo1;
> f = &foo5;
> f = &foo3;
> 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:
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!
So, because foo1 != foo2 !=...foox I would find more appropiate 'add',
'assign', 'register', 'push' more then 'set', or '='
IOW I see operator=() more naturally used between a variable and a
value or another variable of the same type, not to add elements to,
say, a vector.
v = 3;
v = 10;
v = 7;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk