4

I have already implemented and tested the data structure and would now like to make it compatible with the collection of STL algorithms. Guidelines for implementing a custom iterator and the like. Specifically:

  • What is the minimum set of operations that must be supported? (e.g. ++, +=, ==, !=?)
  • Are there any properties of these operations that algorithms expect?

Ideally, these answers would be part of a bigger reference for implementing a STL-compatible data structure, but I'm not sure that such a document exists.

1 Answer 1

5

You should consult the SGI STL documentation. It has detailed requirements for each of the STL components, including containers and iterators.

Effectively, for iterators, there are various types--input iterators, output iterators, forward iterators, bidirectional iterators, and random-access iterators. The specification for each algorithm indicates the type of iterator required.

Sign up to request clarification or add additional context in comments.

2 Comments

Indeed, the categorization on the SGI STL site is really worth referring to. Another option being (when creating a drop-in replacement) to simply provide the same interface as the container being replaced.
Unfortunately, the linked documentation is no longer available. Is there any other such source?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.