This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/5133: Problems with toupper
- From: "Christopher Currie" <christopher at currie dot com>
- To: paolo at gcc dot gnu dot org
- Cc: gcc-prs at gcc dot gnu dot org,
- Date: 28 Jun 2002 04:46:02 -0000
- Subject: Re: libstdc++/5133: Problems with toupper
- Reply-to: "Christopher Currie" <christopher at currie dot com>
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