public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: "Christopher Currie" <christopher@currie.com>
To: paolo@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: libstdc++/5133: Problems with toupper
Date: Thu, 27 Jun 2002 23:14:00 -0000	[thread overview]
Message-ID: <20020628044602.3229.qmail@sources.redhat.com> (raw)

The following reply was made to PR libstdc++/5133; it has been noted by GNATS.

From: "Christopher Currie" <christopher@currie.com>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<paolo@gcc.gnu.org>,
	<schmid@snake.iap.physik.tu-darmstadt.de>
Cc: <philip@codematters.co.uk>,
	<libstdc++@gcc.gnu.org>
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<char>),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 <functional>
 #include <algorithm>
 #include <string>
 #include <locale>
 
 namespace std
 {
 // specialization for the second argument being a reference
 template <class _Arg1, class _Arg2, class _Result>
 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<char>), 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
 


             reply	other threads:[~2002-06-28  4:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-27 23:14 Christopher Currie [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-11-22 14:46 Pete Ratzlaff
2002-11-22 13:48 Martin Sebor
2002-11-22  5:43 Phil Edwards
2002-11-22  5:41 Pete Ratzlaff
2002-11-22  5:11 Pete Ratzlaff
2002-10-31 16:08 paolo
2001-12-17  8:06 Philip Martin
2001-12-16 17:46 Martin Sebor
2001-12-16 15:46 Peter Schmid
2001-12-16 13:53 paolo
2001-12-16 13:16 Peter Schmid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020628044602.3229.qmail@sources.redhat.com \
    --to=christopher@currie.com \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=paolo@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).