|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-11-15 11:47:21
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
[snip]
> Does this make more sense?
This strikes me as an implementation detail. A variable or constant should be
a nullary function object, not an n-ary function object with all n arguments
ignored. If Lambda needs to ignore arguments, it should do it with
a wrapper around ref:
template<typename T>
struct ignore_ref_arguments {
T& operator()() { return m_ref; }
template<typename A>
T& operator()(A&) { return m_ref; }
// more operator()'s... with the same body { return m_ref; }
ref<T> m_ref;
};
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk