How to check libstdc ++ version, not GCC, at compile time?

I am trying to test the libstdc++ version because std::regex implemented, but to a large extent, in versions of libstdc++ distributed with GCC prior to version 4.9.0.

Note that:

Is there any portable way to test a version of libstdc++ that is independent of the use of my GCC compiler?

+6
source share
1 answer

In my opinion, the problem is small enough to be solved by brute force.

In a header file called machine.hpp or similar, I would test that the C ++ Standard version is at least what I need ( __cplusplus macro). Then I would add various macro checks to reject any library that I know has been corrupted.

In other words, instead of the whitelist approach, I would choose the blacklist approach.

For instance:

 #pragma once #ifndef MACHINE_HPP_HEADER_GUARDS #define MACHINE_HPP_HEADER_GUARDS #if __cplusplus < 201103L // Library is incompatible if it does not implement at least the C++11 // standard. #error "I need a library that supports at least C++11." #else // Load an arbitrary header to ensure that the pre-processor macro is // defined. Otherwise you will need to load this header AFTER you // #include the header you care about. #include <iosfwd> #endif #if __GLIBCXX__ == 20150422 #error "This version of GLIBCXX (20150422) has flaws in it" #endif // ...repeat for other versions of GLIBCXX that you know to be flawed #endif // MACHINE_HPP_HEADER_GUARDS 
-2
source

All Articles