[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#144409: g++-3.0: does not support transform(begin,end,begin,tolower) idiom



[Nicolai, if you disagree with the analysis below, please let us know]

Sean Perry <shalehperry@attbi.com> writes:

> the code below is from Josuttis' "The C++ standard library" and I
> have seen it elsewhere.  It works under 2.95.4.

AFAICT, the code is incorrect.

> int main(int argc, char* argv[]) {
>     string foo = "Some Mixed Case Text";
>     cout << foo << endl;
>     transform(foo.begin(), foo.end(), foo.begin(), tolower);

The compiler can't properly resolve "tolower": The problem is that
tolower is not only a function in namespace std, it is also a template
(22.1.3/2). Therefore, in the call to transform, template argument
deduction fails because of the ambiguity.

You can fix your code in the following ways:
1. Define a wrapper function around tolower that you pass to
   transform.
2. Explicitly select the tolower you want to use, by writing

    transform(foo.begin(), foo.end(), foo.begin(), (int(*)(int))std::tolower);

   The cast causes, on the one hand, an explicit overload resolution
   in favour of the function; it also allows the compiler to properly
   deduce the third argument to transform.

Regards,
Martin


-- 
To UNSUBSCRIBE, email to debian-gcc-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: