G
George
Dear All,
I'm compiling the code below with IBM's xlC 6.0 and get the message,
"rmspace.cpp", line 34.48: 1540-0298 (S) Template argument deduction
cannot be performed using the function "template bool
space_pred(basic_string<T,char_traits<T>,allocator<T> >::value_type)".
If I use gcc4.0..2, I get,
rmspace.cpp:34: error: no matching function for call to
'remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'
If I specify space_pred<char> in line 34 instead, gcc compiles. xlC
still does not.
In theory, according to the C++ standard, shouldn't the compiler be
able to deduce the template argument?
(Oh, and I welcome any comments to a better way to remove redundant
spaces....)
-------------------------<coup>---------------------------
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
template <typename T>
bool space_pred(typename basic_string<T>::value_type const & vt)
{
static bool space_found;
const ctype<T>& ct = use_facet<ctype<T> >(locale());
if (ct.is(ctype<T>::space, vt)) {
if (space_found) {
return true;
} else {
space_found = true;
return false;
}
} else {
space_found = false;
return false;
}
}
int main()
{
string gs = "this is a string
with various \
spaces \n and words ";
cout << gs << endl;
// xlc always give the error,
// Template argument deduction cannot be performed for function
'bool space_pred'...
// gcc 4.0.2 will work
gs.erase(remove_if(gs.begin(),gs.end(),space_pred),gs.end());
cout << gs << endl;
return 0;
}
~
~
~
I'm compiling the code below with IBM's xlC 6.0 and get the message,
"rmspace.cpp", line 34.48: 1540-0298 (S) Template argument deduction
cannot be performed using the function "template bool
space_pred(basic_string<T,char_traits<T>,allocator<T> >::value_type)".
If I use gcc4.0..2, I get,
rmspace.cpp:34: error: no matching function for call to
'remove_if(__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > >, <unknown type>)'
If I specify space_pred<char> in line 34 instead, gcc compiles. xlC
still does not.
In theory, according to the C++ standard, shouldn't the compiler be
able to deduce the template argument?
(Oh, and I welcome any comments to a better way to remove redundant
spaces....)
-------------------------<coup>---------------------------
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
template <typename T>
bool space_pred(typename basic_string<T>::value_type const & vt)
{
static bool space_found;
const ctype<T>& ct = use_facet<ctype<T> >(locale());
if (ct.is(ctype<T>::space, vt)) {
if (space_found) {
return true;
} else {
space_found = true;
return false;
}
} else {
space_found = false;
return false;
}
}
int main()
{
string gs = "this is a string
with various \
spaces \n and words ";
cout << gs << endl;
// xlc always give the error,
// Template argument deduction cannot be performed for function
'bool space_pred'...
// gcc 4.0.2 will work
gs.erase(remove_if(gs.begin(),gs.end(),space_pred),gs.end());
cout << gs << endl;
return 0;
}
~
~
~