Issue with ptr_fun VS2008
-
I posted a feedback issue https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=463503 Essentially code that was working in VC6 listed below does not compile: const char* trimChars = "\\/|*?'\"<>;:"; std::remove_if( fileName.begin(), fileName.end(), std::bind1st(std::ptr_fun(strchr),trimChars) ); The only work around I could think of was to wrap strchr inside another function like this: char const* compare(char const* str, int c) { return ::strchr(str,c); } Is this a bug in the compiler or am I missing something? --Joe
If winter comes is spring far behind? - (PBShelley -Ode to the West Wind)
-
I posted a feedback issue https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=463503 Essentially code that was working in VC6 listed below does not compile: const char* trimChars = "\\/|*?'\"<>;:"; std::remove_if( fileName.begin(), fileName.end(), std::bind1st(std::ptr_fun(strchr),trimChars) ); The only work around I could think of was to wrap strchr inside another function like this: char const* compare(char const* str, int c) { return ::strchr(str,c); } Is this a bug in the compiler or am I missing something? --Joe
If winter comes is spring far behind? - (PBShelley -Ode to the West Wind)
Microsoft have added a second overload for strchr (one uses char*, one uses const char*). You need to cast strchr to the function type you need, to disambiguate for ptr_fun. Here, I've used static_cast to specify the const char* variant of strchr.
std::remove_if(fileName.begin(), fileName.end(),
std::bind1st(std::ptr_fun(static_cast<const char*(*)(const char*, int)>(strchr)),
trimChars))Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Microsoft have added a second overload for strchr (one uses char*, one uses const char*). You need to cast strchr to the function type you need, to disambiguate for ptr_fun. Here, I've used static_cast to specify the const char* variant of strchr.
std::remove_if(fileName.begin(), fileName.end(),
std::bind1st(std::ptr_fun(static_cast<const char*(*)(const char*, int)>(strchr)),
trimChars))Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thanks. Like all good ideas it looks obvious after the fact.
If winter comes is spring far behind? - (PBShelley -Ode to the West Wind)