c++ - Is there any way to check whether a function has been declared? -


suppose there's library, 1 version of defines function name foo, , version has name changed foo_other, both these functions still have same arguments , return values. use conditional compilation this:

#include <foo.h> #ifdef use_new_foo #define truefoo foo_other #else #define truefoo foo #endif 

but requires external detection of library version , setting corresponding compiler option -duse_new_foo. i'd rather have code automatically figure function should call, based on being declared or not in <foo.h>.

is there way achieve in version of c?

if not, switching version of c++ provide me ways this? (assuming library needed actions extern "c" blocks in headers)? namely, i'm thinking of somehow making use of sfinae, global function, rather method, discussed in linked question.

in c++ can use expression sfinae this:

//this template enabled if foo declared right args template <typename... args> auto truefoo (args&&... args) -> decltype(foo(std::forward<args>(args)...)) {     return foo(std::forward<args>(args)...); }  //ditto fooother template <typename... args> auto truefoo (args&&... args) -> decltype(fooother(std::forward<args>(args)...)) {     return fooother(std::forward<args>(args)...); } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -