I'm trying to grasp the concept of the iterator. I've run some tests via the following code:
#include <iostream>
#include<map>
using namespace std;
int main(){
map<string,string> mp;//create the map
mp["key"]="value";//create a key/val pair
map<string,string>::iterator it=mp.begin();//create an iterator named it
cout<<(&it)<<" "<<(&*it)<<endl;// 0x7ffeeccd6a18 0x7f9dc5c05970
it++;//moving the current value of the iterator
cout<<(&it)<<" "<<(&*it);// 0x7ffeeccd6a18 0x7ffeeccd6a70
}
To my understanding, we can conceptualize an iterator as a box that holds values - values of the iterable we're iterating over. When we do "it++;" and move the current value of the iterator, we're now accessing a different element, and that's why (&*it) changes. The actual box doesn't change, and that's why (&it) stays the same in both cases (because we're getting the address of the iterator object).
I'm not sure if I understood this correctly, so please tell me if I'm right and correct me if I'm wrong.