Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-13 12:26:41


From: "Jeremy Siek" <jsiek_at_[hidden]>
> On Thu, 13 Dec 2001, Peter Dimov wrote:
> pdimov> From: "Jeremy Siek" <jsiek_at_[hidden]>
> pdimov>
> pdimov> There are several "solutions" to this problem, each with
> pdimov> its own drawbacks. I think I've chosen the least bad.
>
> I'm sure you've already considered the following solution, but let me make
> an argument for it anyways. The following solution makes it possible to
> use bind with return-by-value iterators, but the disadvantage is that some
> erroneous uses of bind no longer result in type errors. In my mind, this
> is a good tradeoff; having bind work in situations when it "should" work
> is more important than getting type errors in situations when it shouldn't
> work.
>
> The solution is simple. Make all the function object operator() parameters
> const &'s and then cast away the const. I know this is sacrilegious, but
> the C++ language has really backed us up into a corner.

Yes, I considered it. It was Brian Parker, I believe, that suggested it
first.

I don't like it. Losing const correctness is a major drawback, IMO, since
the result, in some cases, is undefined behavior. I could live with this
hack if it were absolutely necessary, but it's not, since most iterators
(fortunately) don't return by value.

FWIW the current bind implementation doesn't conform to its spec. :-) The
specification says that it should work even in this case.

> pdimov> For the record, here's my suggestion for a core change:
> pdimov>
> pdimov> "For the purposes of reference binding, all rvalues are considered
const."
>
> Sounds good! Do you want to submit a DR or shall I?

By all means go ahead, but I don't think that a DR will suffice. I suspect
we need a paper. ;-)

--
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