This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/5133: Problems with toupper
- From: Philip Martin <philip at codematters dot co dot uk>
- To: gcc-gnats at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, paolo at gcc dot gnu dot org, schmid at snake dot iap dot physik dot tu-darmstadt dot de, sebor at roguewave dot com
- Date: 17 Dec 2001 16:01:28 +0000
- Subject: Re: libstdc++/5133: Problems with toupper
> #include <string>
> #include <iostream> // does work, when this line is removed
> #include <algorithm>
> #include <cctype>
>
> int main()
> {
> std::string s("Hallo");
> std::transform (s.begin(), s.end(), s.begin(), std::tolower);
> std::transform (s.begin(), s.end(), s.begin(), ::tolower);
> }
Using gcc the include of <iostream> brings in a declaration of the
function template
namespace std { template<class T> T tolower(T, const locale&); }
and the include of <cctype> brings in the functions
extern "C" int tolower(int);
namespace std { using ::tolower; }
[The global scope tolower function is a separate problem, but doesn't
affect this PR.]
Now, I believe you are trying to call the tolower function, rather
than the tolower function template. I don't understand template
argument deduction well enough to be able to say whether the compiler
should work out that this is what you want, but you can tell it
explicitly
typedef std::string::iterator I;
std::transform<I,I,int(*)(int)>transform(s.begin(),s.end(),s.begin(),std::tolower);
This compiles with gcc 3.0.3 and gcc 3.1. However it doesn't address
the "C"/"C++" linkage point mentioned by Martin. One can avoid that by
using the function template, however 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. If you
wish to pursue this you should consider using the bind library from
boost (http://www.boost.org) instead of std::bind2nd
--
Philip