GCC 4.9 和 clang 3.5 中的 std::rbegin 和 std::rend 函数
std::rbegin and std::rend function in GCC 4.9 and clang 3.5
我一直在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;
}
海湾合作委员会输出:
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
它确实可以使用 -std=c++14 -stdlib=libc++
选项与 Clang 3.5 一起使用。请参阅此实时示例。我认为 libstdc++ 库对 rbegin()
和 rend()
的支持尚未完成 4.9.2 版(并且在即将发布的 gcc 5.0 版本中也尚未实现)。
更新:它现在适用于 gcc 5.0 主干版本。
相关文章:
- 使用std::函数映射对象方法
- 可组合的lambda/std::函数与std::可选
- 当使用透明的std函数对象时,我们还需要写空的尖括号吗
- std::函数常量正确性未遵循
- 具有变量Number of Arguments的std::函数的矢量
- 从类型std::函数传递变量失败,尽管调用方期望的类型完全相同
- 如何调用存储在指向"std::函数"的指针中的 lambda?
- C++ STD 函数运算符:有没有一种方法可以通过函数将一个向量映射到另一个向量上?
- 从具有按值捕获的 lambda 移动构造 std::函数时,移动构造函数调用两次
- 如何将类 1 的 std::函数绑定到类 2 的函数?
- 如何制作可以接受任何类型的参数的 std::函数和 lambda
- 如何将 STL 队列推送函数绑定到 std::函数?
- std::函数不起作用,但普通的旧函数指针可以 - 为什么?
- 获取 std::函数以推断按引用传递/按值传递
- std::bind 和 std::函数术语不值为接受 0 个参数?
- 从其存储的回调中删除 std::函数是否安全
- 创建 std::函数,它返回具有函数成员值的变量.分段错误
- 创建一个带有 lambda 的 std::函数,而不知道函数的参数
- std::函数的解释
- 在调用过程中删除 std::函数