Thanks, brewbuck. It now compiles. However, now I have a problem with the behavior of my AnsiCType.
First, here's how I rewrote my code
Code:
const std::ctype<char>* ct;
if(command line argument for locale)
{
std::locale loc(command line argument for locale);
ct = &std::use_facet<std::ctype<char> >(loc);
}
else
{
std::locale loc;
const AnsiCType& act = std::use_facet<AnsiCType>(loc);
ct = &act;
}
const std::ctype<char>& ctr = *ct;
setStr2Id(a map container, a filestream, ctr);
However, even if I use this redefined ctype, it does not properly sort upper ascii letters as "alpha".
Here's my definition of setStr2Id
Code:
template<typename charT>
void setStr2Id
(Str2IdMap& s2i, std::ifstream& ifstr, const std::ctype<charT>& ct){
std::string line;
while(ifstr >> line)
{
const char* const c = line.c_str();
std::string::size_type st = line.size();
if(ct.scan_not(std::ctype_base::alpha, c, c + st) == c + st)
s2i.getId(line);
}
}
Now, when I looked into "ct.scan_not" in my debugger, I got into this:
Code:
const char*
ctype<char>::
scan_not(mask __m, const char* __low, const char* __high) const
{
while (__low < __high
&& (_M_table[static_cast<unsigned char>(*__low)] & __m) != 0)
++__low;
return __low;
}
And while I could not see how _M_table was defined, I am pretty certain that it's not the masking table as I redefined it. So I thought I should try overriding the "scan_not" function in my AnsiCType class. Even then, my program went straight for the "scan_not" in the standard, and not my overridden one.
So how do I get the compiler to use my "scan_not" function or my masking table rather then the predefined one?
By the way, here's my AnsiCType constructor
Code:
AnsiCType::AnsiCType(std::size_t refs)
: std::ctype<char>(ansi_table, false, refs)
{
std::copy(classic_table(),
classic_table() + table_size,
ansi_table);
for(int i = 192; i < 223; i++)
{
if(i != 214)
ansi_table[i] = (mask) (alpha | upper | print | punct);
}
for(int i = 223; i < 256; i++)
{
if(i != 247)
ansi_table[i] = (mask) (alpha | lower | print | punct);
}
}