C ++ does not provide an automated way to handle saving and restoring preprocessor macros. Preprocessor macros (which are not defined from the compiler or the compiler command line) work at the global file level, and there is no concept of restricting the macro area to a specific header, which has the value #include d.
The way I came across such a problem is to create a new header file that provides front-end shells for the function I need from this particular library, but without any macro dependencies. Then implement wrappers in the source file, which includes only this nasty header file.
Your compiler can provide an extension to make the task a little less detailed, but not fully automated as I understand what you mean.
GCC and Microsoft compilers support push pop macros.
For compatibility with Microsoft Windows compilers, GCC supports #pragma push_macro("macro_name") and #pragma pop_macro("macro_name") .
#pragma push_macro("macro_name")
This pragma saves a macro value named macro_name at the top of the stack for this macro.
#pragma pop_macro("macro_name")
This pragma sets a macro value named macro_name to a value on top of the stack for this macro. If the stack for macro_name empty, the macro value remains unchanged.
GCC Documentation
source share