简体   繁体   中英

LLVM&Clang support of C++11

I have some code written by me for MS VC++10. I use C++11 and, in particular, expressions like

std::function<int (int)> f =...;
auto it = v.begin();
for_each(it1, it2,[&](int& i) { ++i;}); 

Now I'm trying out MacOS and XCode with llvm&clang and my code can't be compiled! The question is why? Perhaps, I shall specify an option to use c++11. In this case, where can I fix it in xcode?

You will need Xcode 4.2.

In your build settings, search for "c++0x" and set the "C++ Language Dialect to C++0x [-std=c++0x]". Then search for "libc++" and set the "C++ Standard Library" to "libc++".

Not all C++11 facilities are available. For example lambdas are not yet supported.

For a list of C++11 features Clang currently supports, see this nice list . Lambda expressions (and syntactically related initialzer lists) are currently not implemented.

Your only choice for now (until Clang devs implement lambda support) is using MacPorts' GCC 4.5/4.6 compilers.

The extra command-line option would be -std=c++0x (in the next version of Clang and GCC it will be the proper -std=c++11 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM