#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<int> coll;
decltype(std::begin(std::declval<vector<int>>()))
pos_1 = coll.begin();
auto pos_2 = coll.begin();
cout << typeid(decltype(pos_1)).name() << endl;
cout << typeid(decltype(pos_2)).name() << endl;
}
我的编译器是clang 4.0。输出为:
class std::_Vector_const_iterator> class std::_Vector_iterator>
这意味着:pos_1 = pos_2;
是ok的,而pos_2 = pos_1;
是不ok的。
在这种情况下,为什么std::begin()
const_iterator
总是返回std::begin()
而不是 iterator
?
https://stackoverflow.com/questions/42580761
复制相似问题