Opened 17 years ago

Closed 17 years ago

#63 closed Bugs (Fixed)

regex/tokenizer can't be in same file

Reported by: kiliman Owned by: John Maddock
Milestone: Component: regex
Version: None Severity:
Keywords: Cc:

Description

I'm trying to use regex and tokenizer in the same 
file. I'm using MSVC 6.0SP5, boost lib 1.27. When I 
try to compile, I get the following error:

d:\libs\boost\boost\token_functions.hpp(396) : error 
C2668: 'ispunct' : ambiguous call to overloaded 
function
        d:\libs\boost\boost\token_functions.hpp
(389) : while compiling class-template member 
function 'bool __thiscall 
boost::char_delimiters_separator<char,struct 
std::char_traits<char> >::is_ret(char) const'
Error executing cl.exe.


Here is the code:

#include <iostream>
#include <string>
#include <boost/tokenizer.hpp>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;

int main(int argc, char* argv[])
{
	regex re;

	string s = "This is,  a test";
	tokenizer<> tok(s);

	for(tokenizer<>::iterator beg = tok.begin(); 
beg != tok.end(); ++beg) {
		cout << *beg << "\n";
	}

	return 0;
}


Change History (2)

comment:1 Changed 17 years ago by kiliman

Logged In: YES 
user_id=339840

I'm not sure what is causing the clash between tokenizer 
and regex, but I've come up with a workaround.

I removed the [using namespace std;] statement, and 
explicitly set namespace on call to ispunct and isspace.

    bool is_kept(Char E) const
    {  
      if (m_kept_delims.length())
        return m_kept_delims.find(E) != string_type::npos;
      else if (m_use_ispunct) {
        //using namespace std;
        return std::ispunct(E) != 0;
      } else
        return false;
    }
    bool is_dropped(Char E) const
    {
      if (m_dropped_delims.length())
        return m_dropped_delims.find(E) != 
string_type::npos;
      else if (m_use_isspace) {
        //using namespace std; 
        return std::isspace(E) != 0;
      } else
        return false;
    }
 

comment:2 Changed 17 years ago by John Maddock

Status: assignedclosed
Logged In: YES 
user_id=14804

Fixed in cvs - I've modified tokenizer so that it uses the 
same workaround for BOOST_NO_STDC_NAMESPACE that other 
boost libs use. The workaround suggested is more or less 
correct (there are a few corner cases it doesn't deal with -
 but see the cvs version history for details).
Note: See TracTickets for help on using tickets.