From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3244 invoked by alias); 28 Jun 2002 04:46:04 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 3230 invoked by uid 71); 28 Jun 2002 04:46:02 -0000 Date: Thu, 27 Jun 2002 23:14:00 -0000 Message-ID: <20020628044602.3229.qmail@sources.redhat.com> To: paolo@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: "Christopher Currie" Subject: Re: libstdc++/5133: Problems with toupper Reply-To: "Christopher Currie" X-SW-Source: 2002-06/txt/msg00678.txt.bz2 List-Id: The following reply was made to PR libstdc++/5133; it has been noted by GNATS. From: "Christopher Currie" To: , , , , Cc: , Subject: Re: libstdc++/5133: Problems with toupper Date: Fri, 28 Jun 2002 00:42:34 -0400 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p r=5133 Sorry to dig up this old PR, but it seems to still be in feedback state, and I've been working with the problem recently and I wanted to weigh in. Philip Martin wrote: > using the function template is > tricky because the second parameter is a reference. One would like to > try > > // this won't work > std::locale loc; > std::transform(s.begin(),s.end().s.begin(), > std::bind2nd(std::ptr_fun(std::tolower),loc)); > > but this will suffer from the reference to a reference problem. Without going into too much detail, the problem is detected in binder2nd's constructor, but can be traced to the definition of the binary_function template. I was able to get the above code working by adding a specialization of the template, used when the second argument is a reference: #include #include #include #include namespace std { // specialization for the second argument being a reference template struct binary_function<_Arg1, _Arg2&, _Result> { typedef _Arg1 first_argument_type; typedef _Arg2 second_argument_type; typedef _Result result_type; }; } int main() { using namespace std; string s ("Someone Chanted Evening"); locale loc; transform(s.begin(), s.end(), s.begin(), bind2nd(ptr_fun(&tolower), loc)); return 0; } Naturally, a second specialization would be necessary for the first argument, so that bind1st will also behave as expected. The remaining questions: Does this specialization violate the Standard, and/or will it break existing code? Comments and criticisms welcome. Christopher Currie