C++ check if typedef if defined

1.5k views Asked by At

I am linking a project to a library. Depending on the version of the library, some API and typedef are different.

There is no way to extract the library version. I would like at compile time to determine the version of this library and define a corresponding preprocessor variable.

More precisely, I would like something as following

#ifdef size_type
#define LIBRARY_VERSION 1.0
#else
#define LIBRARY_VERSION 2.0
#endif

The problem is that size_type is not a macro but a type defined using a typedef. How can I do it?

1

There are 1 answers

2
2501 On

Use an accompanying macro at the location where the typedef is defined.

typedef size_t size_type ;
#define size_type_defined

#ifdef size_type_defined
#define LIBRARY_VERSION 1.0
#else
...

You will need to write an additional line, but only once.