Iterator:可读可写得迭代器类型?
std::vector<int> b {1,2,3};
auto d = b.begin();
std::cout<< typeid(d).name()<<std::endl;
N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEE
const_iterator:只读不可写迭代器类型,注意看,打印出来的?“N9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEE”和iterator类型是有区别的,在iteratorI后面的修饰是PKi表示指针,常量 整数,而iterator是是Pi,表示指针,整数,这里的i取决于模板类型<T>
std::vector<int> b {1,2,3};
auto m = b.cbegin();
std::cout<< typeid(m).name()<<std::endl;
N9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEE
?比如
std::vector<char> b {3};
auto m = b.cbegin();
std::cout<< typeid(m).name()<<std::endl;
N9__gnu_cxx17__normal_iteratorIPKcSt6vectorIcSaIcEEEE
?
difference_type:表示两个迭代器之间的距离,有符号?
std::vector<int> b {1,2,3};
auto k = b.end()-b.begin();
std::cout<< typeid(k).name()<<std::endl;
x
|