GCC 4.9 和 clang 3.5 中的 std::rbegin 和 std::rend 函数

std::rbegin and std::rend function in GCC 4.9 and clang 3.5

本文关键字:std 函数 rend rbegin 中的 clang GCC      更新时间:2023-10-16

我一直在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 主干版本。