Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Issue with ptr_fun VS2008

Issue with ptr_fun VS2008

Scheduled Pinned Locked Moved C / C++ / MFC
helpjavacombeta-testingquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    parama_chakra
    wrote on last edited by
    #1

    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)

    S 1 Reply Last reply
    0
    • P parama_chakra

      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)

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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

      P 1 Reply Last reply
      0
      • S Stuart Dootson

        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

        P Offline
        P Offline
        parama_chakra
        wrote on last edited by
        #3

        Thanks. Like all good ideas it looks obvious after the fact.

        If winter comes is spring far behind? - (PBShelley -Ode to the West Wind)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups