regex and tokenizer, something wrong with namspace ?
Hi, I am a new user of the boost library (Actually with VC6 SP5 and stlport 4.0). Everything goes well when I use tokenizer and regexp in separated programs. But when I want to use the regex and the tokenizer library together I can not compile. for example, if I take the $(BOOST_ROOT)/libs/tokenizer/examples.cpp from John R. Bandela and just add the include line: #include <boost/regex.hpp> the compiler gives me this error: Compiling... examples.cpp c:\program files\microsoft visual studio\vc98 \include\boost\token_functions.hpp(264) : error C2668: 'ispunct' : ambiguous call to overloaded function c:\program files\microsoft visual studio\vc98 \include\boost\token_functions.hpp(257) : while compiling class- template member function 'bool __thiscall boost::char_delimiters_separator<char,class _STL::char_traits<char>
::is_ret(char) const' Error executing cl.exe.
examples.exe - 1 error(s), 0 warning(s) any idees ? Alexandre
But when I want to use the regex and the tokenizer library together I can not compile. for example, if I take the $(BOOST_ROOT)/libs/tokenizer/examples.cpp from John R. Bandela and just add the include line:
#include <boost/regex.hpp>
the compiler gives me this error: ...
I suspect the problem may either be a compiler or configuration issue. I tried out your experiment with boost_1_25_0, g++ 2.95.2 under cygwin, and STLPort4.0 and it compiles fine. Just searching the header files, there is only one ispunct (which is defined in std::) and that is in token_functions.hpp, so there is no direct clash between the libraries. Good luck, Jeff
Thanks Jeff, but I guess it is this stupid MSVC compiler. I just done what I does not want to do (but it works fine), turning using namespace directive into scope resolution operator inside "token_functions.hpp": bool is_ret(Char E)const { if(returnable_.length()) return returnable_.find(E) != string_type::npos; else{ if(no_ispunct_){return false;} else{ //using namespace std; //int r = ispunct(E); int r = std::ispunct(E); return r != 0; } } } bool is_nonret(Char E)const { if(nonreturnable_.length()) return nonreturnable_.find(E) != string_type::npos; else{ if(no_isspace_){return false;} else{ //using namespace std; //int r = isspace(E); int r = std::isspace(E); return r != 0; } } } I try this little program inside MSVC and it work fine. I does not understand what is going on inside "token_functions.hpp"! #include <string> #include <iostream> void f(); int main(int argc, char* argv[]) { f(); return 0; } #define xxx std; void f() { using namespace xxx; string a; a.assign("hello"); cout << a << endl; }
Alexandre -
Thanks Jeff, but I guess it is this stupid MSVC compiler. I just done what I does not want to do (but it works fine), turning using namespace directive into scope resolution operator inside "token_functions.hpp":
Actually, I believe std::ispunct is a better implementation than the current one that uses "using". Just so I understand, did this change work? If so, it should be suggested as a change to the library.
I try this little program inside MSVC and it work fine. I does not understand what is going on inside "token_functions.hpp"!
#include <string> #include <iostream>
void f();
int main(int argc, char* argv[]) { f(); return 0; }
#define xxx std;
void f() { using namespace xxx; string a; a.assign("hello"); cout << a << endl; }
I don't understand what you are trying to do here or what this has to do with regex/tokenizer? Jeff
Actually, I believe std::ispunct is a better implementation than the current one that uses "using". Just so I understand, did this change work? If so, it should be suggested as a change to the library.
I don't think so. I think that we must understand what going on because the piece of code below works neither with std:: and namespace (on MSVC6)! #include<iostream> #include<boost/tokenizer.hpp> #include<string> using namespace std; using namespace boost; int main(int, char**){ string s = "c:\\temp\\toto\\|a<x>fdl\\|*.doc"; //"This| is, a\\| $|test"; ////////////////////////////////////////////////////////////////////// only works with "using namespace std" typedef tokenizer<escaped_list_separator<char> > token_type; token_type tok(s, escaped_list_separator<char>('$', '|', '\"')); for(token_type::iterator beg=tok.begin(); beg!=tok.end();++beg){ cout << *beg << "\n"; } // (the code above is a test and I does not understand what it does // but it does not matter for what we are looking for!) ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// only works with "std:: operator" typedef tokenizer<char_delimiters_separator<char> > token_type; token_type tok(s, char_delimiters_separator<char>(false, 0, "|")); for(token_type::iterator beg=tok.begin(); beg!=tok.end();++beg){ cout << *beg << "\n"; } ////////////////////////////////////////////////////////////////////// return 0; }
I don't understand what you are trying to do here or what this has to do with regex/tokenizer?
I readed that boost turns _STD:: into std:: with macro, so I try the same in my small test program just trying to see if using namespace directive inside a brace's bloc is supported by the MSVC compiler. Alex ___________________________________________________________ Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français ! Yahoo! Courrier : http://courrier.yahoo.fr
I readed that boost turns _STD:: into std:: with macro, so I try the same in my small test program just trying to see if using namespace directive inside a brace's bloc is supported by the MSVC compiler.
Ok, now I understand this part, but just to clarify, it is STLPort not Boost that uses this macro. Jeff
Ok, now I understand this part, but just to clarify, it is STLPort not Boost that uses this macro.
Thanks for correct me, I'am just tired working since this morning (and it is now 18h in France)! And what about the other part ? ___________________________________________________________ Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français ! Yahoo! Courrier : http://courrier.yahoo.fr
Thanks for correct me, I'am just tired working since this morning (and it is now 18h in France)! And what about the other part ?
Well, I don't see anything obviously wrong, but if I were you I would try taking out all the using statements and qualify all the names. I'm not an expert on the issues with MSVC, but I suspect that 'using' may have more problems than directly qualified names. And if that doesn't work I would get some rest :-) Jeff
participants (3)
-
acarsac@yahoo.fr
-
Alexandre Carsac
-
Jeff Garland