Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a preprocessor directive for detecting C++11 Standard library?

Is it possible to determine if C++ standard library has C++11 support using a preprocessor directive?

I'm currently working on a project which uses the C++11 language dialect, but with the a C++ standard library without C++11 support (I need this to be able to link with non C++11 libraries).

I'm aware of that I can test of C++11 support using the #if __cplusplus >= 201103L, but in my case this will evaluate to true. I need to know about the C++ standard library support for C++11.

like image 446
Mortennobel Avatar asked Jul 19 '13 11:07

Mortennobel


2 Answers

Testing for features is an active research direction for the Standard Committee going towards the next C++14 Standard (and beyond that). There is a Study Group 10 with its own freely accessible mailinglist where current development is being discussed. For the next meeting, this N3694 working paper has been submitted.

like image 151
TemplateRex Avatar answered Nov 08 '22 04:11

TemplateRex


My problem was on the iOS platform where the choice of C++ standard library was between libstd++ (GNU C++ standard library) and libc++ (LLVM C++ standard library with C++11 support). I ended up using the _GLIBCXX_. The complete code ended up being:

#ifndef _GLIBCXX_
template <class T>
T&& move (T& arg) noexcept {
    return static_cast<T&&>(arg);
}
#endif
like image 3
Mortennobel Avatar answered Nov 08 '22 04:11

Mortennobel