简体   繁体   中英

how to get C++0x / C++11 style range-based for loops to work with clang?

I've been taking advantage of range-based for loops in C++0x/11 using gcc w/ -std=c++0x like so:

for (int i : container) ...

I recently tried clang (clang+llvm-2.9-x86_64-apple-darwin10), but out-of-the-box these statements were compilation errors. According to http://clang.llvm.org/cxx_status.html it's supported. I tried adding -stdlib=libc++ on the command-line, but then I get an error that the iostream header isn't found. What do I need to do to get clang to work with C++0x/11 functionality?

The secret here is that LLVM 2.9 doesn't support range-based for loops. That document corresponds to LLVM/Clang mainline. To get range-based for loops, please check out LLVM/Clang from mainline SVN: http://clang.llvm.org/get_started.html

libc++ is useful for C++'0x ('11!) library support, but you also have to set it up if you want to use its functionality on top of C++'0x language features. For information on how to set it up, please see: http://libcxx.llvm.org/

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