Topic: Missing binders for non-const sequence elements
Author: sankar@rahu.miel.mot.com (Sankaranarayanan KV[M])
Date: 1999/11/09 Raw View
Hi,
This question is regarding the C++ standard library open issue submitted
by Bjarne Stroustrup on missing binders for non-const sequence elements.
Refer
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html
issue numbered 109.
The issue says
There are no versions of binders that apply to non-const elements of a
sequence. This makes examples like for_each() using bind2nd() on page
521 of "The C++ Programming Language (3rd)" non-conforming. Suitable
versions of the binders need to be added.
The proposed resolution seems to have some deficiencies.
The proposed solution adds application operators taking non-const
arguments to binder1st and binder2nd. The new application operator member
functions are also declared const like the earlier ones.
This alone is not adequate for the following reasons:
1. Since the application operator is declared const, the first argument
(the bound argument held in the binder object) cannot be passed as a
non-const reference. That is, the proposed solution only considers
the second argument being passed as non-const reference.
2. Let us assume that we have to bind a functor F having
void operator()(T1& t1, T2& t2);
T1 and/or T2 could be in-out arguments. Passing values (x1, y1) might
yield different values (x2, y2). Such a function may be bound with a
T1 argument having value x1. The binder may be passed to an algorithm
like:
F f(...); // construct
T1 t1 = x1;
Vector<T2> v;
// fill up v having values y1, y2, ..., yn.
for_each(v.begin(), v.end(), bind1st(f, t1));
Our intention is this:
(x1, y1) yields a new x2.
That x2 is applied next with y2 given by for_each, yielding x3, and
so on.
After the algorithm application we would like to have the value xn
for t1.
However, this is _not_ possible with the current specs of
binders. The bind argument is copied and held private. Instead, it
should have been held by reference in this case. The constructor
needs to take a reference and hold it by reference.
I would like to have your comments on this.
I know that (to quote from the web page):
A Proposed Resolution for an open issue is still not be construed as
the view of LWG. Comments on the current state of discussions are often
given at the end of open issues in an italic font. Such comments are for
information only and should not be given undue importance. They do not
appear in the public version.
but I would like to know the current thoughts of the working group on
this issue.
Thanks!
Regards
Sankar
--
Sankaranarayanan K. V. Motorola India Electronics Ltd.
Senior Software Engineer "The Senate," 33A Ulsoor Road
tel: +91-80-559-8615 ext 4047 Bangalore, Karnataka
fax: +91-80-559-8660 India 560 042
mailto: sankar@miel.mot.com http://www.mot.com/miel
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]