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

I used std :: rbegin and std :: rend in MSVC 2013. When I tried to compile my code using GCC 4.9.1 or clang 3.5.0, both tell me that 'rbegin' and 'rend' are not in space the names 'std'.

See the sample code below. Am I doing something wrong or are they just not yet implemented in GCC and 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 Output:

 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) { ^ 

The output of clang is similar, generated using

 clang++ --std=c++14 test.cpp -o test && ./test 
+6
source share
1 answer

It works with Clang 3.5 with the option -std=c++14 -stdlib=libc++ . See Live example . I think that support for the libstdC ++ library for rbegin() and rend() is not yet complete as version 4.9.2 (and also not yet implemented in the gcc 5.0 release ).

UPDATE : it now works in trunk gcc 5.0 release.

+5
source

Source: https://habr.com/ru/post/980925/


All Articles