65,187
社区成员




#include <list>
#include <iostream>
int main(){
list<int> lst;
for(list<int>::iterator itor=lst.begin();itor!=lst.end();itor++){
cout<<(*itor)<<endl;
//do something
}
}
for(auto &node:lst){
cout<<node<<endl;
//do something
}
/**
* Returns a read/write iterator that points one past the last
* element in the %list. Iteration is done in ordinary element
* order.
*/
iterator
end() _GLIBCXX_NOEXCEPT
{ return iterator(&this->_M_impl._M_node); }
iterator end()noexcept
//{ return iterator(this->m_table,this->m_table.capacity); }//原代码
{
cout << "return a end iterator" << endl;//输出调试信息
return iterator(this->m_table, this->m_table.capacity);
}
HashSetCl<int> testhash;//HashSetCl是基于HashTableAbstract子类,实现哈希集合
testhash.insert(2000);//加入3条数据
testhash.insert(65535);
testhash.insert(12345);
cout<<"testing for statement using iterator:"<<endl;//使用迭代器循环
for (auto itor = testhash.begin(); itor != testhash.end(); itor++) {
cout << *itor << endl;
}
cout<<"testing for the range-base for statement:"<<endl;//使用基于范围的for循环
for (auto n : testhash) {
cout << n << endl;
}
for(auto itor=lst.begin(),end=lst.end();itor!=end;itor++){
cout<<(*itor)<<endl;
//do something
}
{
auto && __range = range-init;
for ( auto __begin = begin-expr,
__end = end-expr;
__begin != __end;
++__begin ) {
for-range-declaration = *__begin;
statement
}
}