Why is operator-> implemented by operator * in STL STL library?

I read the source code std::deque

, I found the following implementations for _deque_iterator::operator->

and_deque_iterator::operator*

reference operator* const() { return *cur; }
pointer operator-> const(){ return &(operator*()); }

      

So my question is, why not just return a pointer cur

? Like this:

pointer operator-> const(){ return cur; }

      

+3


source to share


1 answer


It's more flexible.



If something changes, you just need to make changes in one place. If you go back cur

(as you suggested, you have two places that you must change.

+5


source







All Articles