Ho utilizzato std :: rbegin e std :: rend in MSVC 2013. Quando ho provato a compilare il codice utilizzando GCC 4.9.1 o clang 3.5.0, entrambi mi dicono che 'rbegin' e 'rend' non fanno parte dello spazio dei nomi 'std'.std :: rbegin e std :: esegue la funzione in GCC 4.9 e clang 3.5
Vedere l'esempio di codice riportato di seguito. Sto facendo qualcosa di sbagliato o semplicemente non sono ancora stati implementati in GCC e 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;
}
uscita 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) {
^
uscita clang è simile, generata con:
clang++ --std=c++14 test.cpp -o test && ./test
Stai confrontando GCC con Clang ma entrambi utilizzano libstdC++ per impostazione predefinita ed è in realtà l'implementazione della libreria standard che dovresti confrontare. –