Checking for availability of C++0x algorithm additions
Asked Answered
N

2

3

I'm trying to figure out which of the additions to the algorithm headers are supported by a given implementation (gcc and MSVC would be enough).

The simple way would be to do it the same way as one would do it for core features: check the compiler version and define a macro if a language feature is supported. Unfortunately I cannot find a list that shows the version numbers for either compiler.

Is simply checking for a generic C++0x macro (GXX_EXPERIMENTAL or __cplusplus) enough or should I check the change lists for the compilers and build my macros based on those lists?

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x

Noonday answered 23/5, 2011 at 10:21 Comment(1)
For MSVC, the macros _MSC_VER and _MSC_FULL_VER are documented here.Nims
C
2

Since all compiler vendors provide a nice list of what's available in what version, and you would test the functionality anyways, I would use compiler versions to check for specific features. Or demand the user uses at least a good version, and not worry about it.

__cplusplus is not necessarily a C++0x macro, it tells you nothing. GXX_EXPERIMENTAL has existed since GCC 4.3, so that's pretty useless too.

Here you can find what macros to check against for a specific version of a compiler.

Cecilius answered 23/5, 2011 at 10:32 Comment(2)
Please re-read the question since it specifically not about core language features, which are in most cases nicely listed, but about library features. The gcc list for library features only lists "implemented yes/no" but no version. I couldn't even find anything about MSVC.Noonday
@pmr: OK, I may have misread the question. If it's not in the lists, all you can do is try it out and see with every compiler you plan to support. If you don't really need Windows support, you can always use libc++, which is a complete c++0x/11 Standard library implementation. It only currently works on Mac and Linux (perhaps BSDs as well).Cecilius
N
0

As far as I could figure out the only proper solution is to have a build script that tries to compile and run a file that uses the feature and has a runtime assertion. Depending on the outcome have a #define CONFIG_NO_FEATURENAME or similiar in a config file and guard your uses and workaround with a #ifndef.

This way it is possible to check if

  1. the feature is available
  2. the feature functions properly (depending on the correctness of the assertion)
Noonday answered 24/5, 2011 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.