I’m writing a few classes and structs that could benefit from 16-byte alignment. Instead of using compiler-specific hacks, I’d rather use the new C++0x alignas functionality for future portability. However, using it outside of appropriate #ifdef or #ifndef guards will obviously cause errors on compilers without alignas support.
I did a quick search for similar questions, and the closest match had an answer recommending Boost.Config. Unfortunately, Boost.Config doesn’t seem to include any functionality for querying alignas support. Are there any other #ifdefs or #ifndefs I can use to figure out whether the compiler supports it?
Thanks!
There are no direct feature-support macros for the various C++0x (C++11) facilities. There only two ways I can think of to determine their presence.
#ifdefdirectives based on the compiler-supplied version macros such as__GNUC__and_MSC_VER, orUsing Boost.Config is actually an example of both: Boost has a set of feature-detection scripts which are run during Boost development, and then the results hard-coded in the Boost.Config headers based on the compiler version macros.