
Boost : 
From: Peter Dimov (pdimov_at_[hidden])
Date: 20011115 12:08:14
From: "Douglas Gregor" <gregod_at_[hidden]>
> On Thursday 15 November 2001 11:08 am, you wrote:
> > std::for_each(v.begin(), v.end(), ref(x) += _1);
> >
> > ref(x) is a function object such that ref(x)(y) returns a reference to
x.
> > _1(y) returns a reference to y. (E1 += E2)(y) returns E1(y) += E2(y). So
>
> This strikes me as an implementation detail.
Let me see if I understand you correctly. You are saying that operator+=
(and all other operators) should explicitly check for ref() and wrap it in
an appropriate argumentignoring function object.
A possible approach. What are its advantages?
> A variable or constant should be
> a nullary function object, not an nary function object with all n
arguments
> ignored.
This doesn't really fit the current Lambda (and Bind) spirit. Since the
argument list is not specified,
lambda() { return x; }
lambda(a) { return x; }
lambda(a, b) { return x; }
lambda(a, b, c) { return x; }
are all spelled
ref(x)
and similarly,
lambda(a) { return a; }
lambda(a, b) { return a; }
lambda(a, b, c) { return a; }
are all spelled _1.
Composition works the same way:
lambda(argumentlist) { return E1(argumentlist) @ E2(argumentlist); }
is spelled
E1 @ E2;
So lambda expressions don't have arity. They act on arbitrary argument
tuples. That's why ref(x) can take any arguments.
Note that I don't have a vested interest in this matter; I'm simply trying
to keep ref/bind compatible with LL hoping that people will painlessly
transition to LL when its time comes.
 Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk