c++ - How to work with stl with functor wrap of function pointer? -
i need use unordered_map function pointer passing in, there workaround can make following code work?
struct eq_fun { bool operator()(void* s1, const void* s2) const { return ( _cmp_fn((void*)s1,(void*)s2) == 0 ); } int (*_cmp_fn)(void*, void*); eq_fun(int (*fn)(void*, void*)):_cmp_fn(fn){} }; struct hash_fun { size_t operator()(const void *p) const { return _hash_fn(p); } int (*_hash_fn)(const void*); hash_fun(int (*fn)(const void*)):_hash_fn(fn){} }; unordered_map<void*,void*> *create(int (*h)(const void*),int (*cmp)(void*,void*)) { return new unordered_map<void*,void*,hash_fun(h),eq_fun(cmp)>; }
sure
unordered_map<void*,void*,hash_fun, eq_fun> *create(int (*h)(const void*),int (*cmp)(void*,void*)) { return new unordered_map<void*,void*,hash_fun,eq_fun>(0, hash_fun(h), eq_fun(cmp)); }
seems unordered_map not have constructor takes hash function , equaility function, i've added minimum number of buckets parameter value of zero. in case important point construct function objects separately , pass objects unordered_map constructor.
Comments
Post a Comment