简体   繁体   English

如何获得基于C ++ 0x / C ++ 11样式范围的循环以与clang一起工作?

[英]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: 我一直在使用gcc w / -std = c ++ 0x在C ++ 0x / 11中利用基于范围的for循环,如下所示:

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. 我最近尝试了clang(clang + llvm-2.9-x86_64-apple-darwin10),但是现成的这些语句是编译错误。 According to http://clang.llvm.org/cxx_status.html it's supported. 根据http://clang.llvm.org/cxx_status.html的支持。 I tried adding -stdlib=libc++ on the command-line, but then I get an error that the iostream header isn't found. 我尝试在命令行上添加-stdlib = libc ++,但是随后出现一个错误,即找不到iostream标头。 What do I need to do to get clang to work with C++0x/11 functionality? 我需要做什么才能使clang与C ++ 0x / 11功能一起使用?

The secret here is that LLVM 2.9 doesn't support range-based for loops. 这里的秘密是LLVM 2.9不支持基于范围的for循环。 That document corresponds to LLVM/Clang mainline. 该文档对应于LLVM / Clang主线。 To get range-based for loops, please check out LLVM/Clang from mainline SVN: http://clang.llvm.org/get_started.html 要获取基于范围的循环,请从主线SVN中检出LLVM / Clang: 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. libc ++对于C ++'0x('11!)库支持很有用,但是如果要在C ++'0x语言功能之上使用它的功能,则还必须进行设置。 For information on how to set it up, please see: http://libcxx.llvm.org/ 有关如何设置的信息,请参见: http : //libcxx.llvm.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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