find_if and ptr_fun(isspace<char>) trouble

Gabriel Dos Reis gdr@integrable-solutions.net
Sun Dec 19 15:48:00 GMT 2004


Dan Kegel <dank@kegel.com> writes:

| I'm trying to port somebody else's code from g++-2.95.3 to g++-3.4.1, but am
| running into template problems with STL algorithms and ptr_fun(isspace<char>).
| 
| Compiling the following snippet:
| 
| #include <cctype>
| #include <functional>
| #include <algorithm>
| #include <deque>
| #include <locale>
| using namespace std;
| int main ()
| {
|          char     init[7] = {1,2,3,4,5,6,7};
|          deque<char> d(init, init+7);
|          find_if (d.begin(), d.end(), ptr_fun(isspace<char>));

The code is wrong because it pulls in two version of isspace
 
  * one in <cctype> -- the traditional C function;
  * another in <locale> -- the C++ only version that takes two
       arguments: the locale and the character.

and then is trying to use the second version in place of the first.

Try to add

     struct Isspace {
        bool operator()(int c) const { return isspace(c); }
     };

and try

      find_if (d.begin(), d.end(), Isspace());

Also hae a look at:

    http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/howto.html#4

-- Gaby



More information about the Gcc-help mailing list