【发布时间】:2015-01-13 12:24:32
【问题描述】:
我一直在 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;
}
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) {
^
clang 输出类似,生成:
clang++ --std=c++14 test.cpp -o test && ./test
【问题讨论】:
-
您正在比较 GCC 和 Clang,但默认情况下两者都使用 libstdc++,这确实是您应该比较的标准库实现。
标签: c++ gcc iterator clang c++14