2015-01-13 13 views
6

MSVC 2013でstd :: rbeginとstd :: rendを使用しています。GCC 4.9.1を使用してコードをコンパイルしようとしたとき、 3.5.0では、両方とも 'rbegin'と 'rend'が名前空間 'std'の一部ではないことを教えてくれます。std :: rbeginとstd :: rendはGCC 4.9とclang 3.5で機能します

は、次のコード例を参照してください。私は何か間違っているのですか、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++ --std=c++14 test.cpp -o test && ./test 
+0

あなたはクランでGCCを比較しているが、両方は、デフォルトでのlibstdC++を使用し、それは本当にあなたが比較されなければならない標準ライブラリの実装です。 –

答えて

5

それは-std=c++14 -stdlib=libc++オプションを使用してクラン3.5で動作しません。このLive Exampleを参照してください。私はrbegin()rend()のlibstdC++ライブラリサポートは、バージョン4.9.2としてまだ完成していないと思う(それもnot yet implemented in the upcoming gcc 5.0リリースである)。

UPDATE:gcc 5.0トランクリリースで動作するようになりました。

+0

そうですね、libstdC++にはまだありません。 –

+2

[ドキュメントに従う](http://en.cppreference.com/w/cpp/iterator/rbegin)は、C++ 14の新機能です。私はまだそれはまだ実装されていない驚いています。 – sjdowling

+0

@LightnessRacesinOrbit今後のgcc 5にはそれがあると思います。それを示すオンラインコンパイラが見つかりませんでした。 – TemplateRex

関連する問題