Suppose there is a library, one of which defines a function named foo , and the other version has a name changed to foo_other , but both of these functions still have the same arguments and return values. I am currently using conditional compilation as follows:
#include <foo.h> #ifdef USE_NEW_FOO #define trueFoo foo_other #else #define trueFoo foo #endif
But this requires some external detection of the library version and setting the appropriate compiler option, for example -DUSE_NEW_FOO . I would prefer the code to automatically determine which function it should call based on the declaration or not in <foo.h> .
Is there a way to achieve this in any version of C?
If not, will any way to do this switch to any version of C ++? (assuming the library performs all the necessary actions, such as extern "C" blocks in its headers)? Namely, Iβm thinking about somehow using SFINAE , but for the global function, not the method that was discussed in the related question.
source share