简体   繁体   中英

C++ STL iterator interface

I know that the STL library uses different kind of iterators to traverse his containers: input, output, forward, bidirectional and random access.

I also know that iterators abstact the classic c pointer interface. So an iterator class must have the ++, * operators and so on (to act like a pointer).

Is the interface for every kind of iterator written in some specification? Is this interface just a convention used in the STL library or is there some hierarchy of classes from which I should extend my iterators?

From what I understand, I should just 'copy' the interface conventions followed in the STL library to be able to use my iterators with it.

You can lookup each iterator category interface requirements from iterator page.

As already mentioned, people often don't bother implementing the entire iterator interfaces from scratch, but use boost::iterator library for taking care of the boilerplate code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM