How to hash and compare a pointer-to-member-function?

前端 未结 3 844
無奈伤痛
無奈伤痛 2020-11-27 08:23

How can i hash (std::tr1::hash or boost::hash) a c++ pointer-to-member-function?

Example:

I have several bool (Class::*functionPointer)() (not static) that

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 08:41

    I could not cast the pointer (in Microsoft compiler 2010)as described in previous answer but this works for me:

    static string fmptostr(int atype::*opt)
      {
          char buf[sizeof(opt)];
          memcpy(&buf,&opt,sizeof(opt));
          return string(buf,sizeof(opt));
      }
    

    About bitwise identity of the pointer, it can be bitwise so it seems if appropriate compiler switches are used. At least this is true for Microsoft compiler E.g using #pragma pointers_to_members and a switch.../vmg

提交回复
热议问题