when implementing insert function in general pair<iterator,bool> is returned is stl library
I am implementing stl -like class .can I return in the pair an iterator as local variable i.e.
itartor it;//init it
return pair<iterator,bool>(it,true);
or should I dynamically allocate iterator i.e.:
itartor it = new iterator;
return pair<iterator,bool>(*it,true);
You should use the first option. There is no reason whatsoever for the second, since you are dereferencing the pointer anyway. And leaking memory:
Standard library iterators are designed to be passed by value. You should make sure your iterators are cheap to copy, and avoid all dynamic memory management pitfalls.