This question already has an answer here:
- How to allow range-for loop on my class? [duplicate] 3 answers
I am writing a class that contains a collection of child objects of the same class and would like to iterate, and index, through them using the standard-provided functions instead of functions like: first()
, next()
, previous()
, last()
, getchild(x)
etc.
In c++14, which functions must I implement to make a class iterable/indexable in all cases?
The functions:
begin()
cbegin()
rbegin()
crbegin()
end()
cend()
rend()
crend()
come to mind, although, probably not necessarily all of them need be implemented. Also optionally (for programmer convenience):
size()
empty()
Are there any other functions that I must implement, like the pre-increment/decrement or post-increment/decrement and array subscript operators, or is it really just begin()
and end()
and their variants?