Pet*_*r K 6 c++ gcc iterator clang c++14
我一直在MSVC 2013中使用std :: rbegin和std :: rend.当我尝试使用GCC 4.9.1或clang 3.5.0编译我的代码时,两者都告诉我'rbegin'和'rend'不属于命名空间'std'.
请参阅下面的代码示例.我做错了什么还是他们还没有在GCC和clang中实现?
// test.cpp
#include <vector>
#include <iostream>
#include <iterator>
int main(int, char**)
{
std::vector<int> test = {1, 2, 3 ,4, 5};
for (auto it = std::rbegin(test); it != std::rend(test); ++it) {
std::cout << *it << ", ";
}
std::cout << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC输出:
g++ --std=c++14 test.cpp -o test && ./test
test.cpp: In function ‘int main(int, char**)’:
test.cpp:10:20: error: ‘rbegin’ is not a member of ‘std’
for (auto it = std::rbegin(test); it != std::rend(test); ++it) {
^
test.cpp:10:45: error: ‘rend’ is not a member of ‘std’
for (auto it = std::rbegin(test); it != std::rend(test); ++it) {
^
Run Code Online (Sandbox Code Playgroud)
clang输出类似,生成:
clang++ --std=c++14 test.cpp -o test && ./test
Run Code Online (Sandbox Code Playgroud)
它使用该-std=c++14 -stdlib=libc++选项与Clang 3.5一起使用.看到这个实例.我认为libstdc ++库支持rbegin()并且rend()尚未完成4.9.2版本(在即将发布的gcc 5.0版本中它还没有实现).
更新:它现在在gcc 5.0 trunk版本中运行.
| 归档时间: |
|
| 查看次数: |
1305 次 |
| 最近记录: |