jeudi 27 août 2015

creating a generic wrapper that returns either std::mem_fn or boost::mem_fn

I've inherited something that's way above my current whatevafu :

The KDE/PIM Zanshin project uses std::mem_fn in a number of locations throughout its code, and it turns out that at least 1 version of Apple's clang (the one shipped with the latest Xcode available for OS X 10.9) generates object code that fails to link for a number of the files involved.

It turns out to be possible to circumvent the issue by using boost::mem_fn instead of std::mem_fn . The project's main author is not inclined to increase the boost dependency on all platforms, so I proposed a patch in which a conditional macro is used that expands to boost::mem_fn when required.

The request is now to create a template function that lives in one of zanshin's own namespaces (Utils::mem_fn(f)) and that returns either std::mem_fn(f) or boost::mem_fn(f). And that's the part that's either way above my current paygrade ... or that is simply not feasible independent of the fact that I hardly even understand the purpose of the mem_fn function.

So the question is: is there an easy, compact way to wrap std::mem_fn, ideally with a single template function?

The main hurdle appears to be the return type, but since all uses in zanshin's code appear to return what boils down to a function pointer, I tried using a void* return type. I expected that to fail, and indeed it did.

Thanks in advance...

Aucun commentaire:

Enregistrer un commentaire