Is an iterator a type?

closed account (EwCjE3v7)
I wondered if an interator was a type? Or is it a function?
Thanks you
It is a type category: if a type satisfies the set of requirements for iterators, listed here for example http://en.cppreference.com/w/cpp/concept/Iterator
then it is an iterator.
Last edited on
if you look at you header files, it's something like :

1
2
3
4
5
6
7
8
template <class T, size_t size>
class array {
    typedef T value_type;
    typedef value_type* iterator;  // <=== HERE
    typedef const value_type* const_iterator;

    // blah blah
};
Last edited on
Each container normally has their own iterator types (const and non-const).

shadow fiend wrote:
it's a pointer

It's not always a pointer. Only containers that store the elements in sequence in an array can use pointers as iterators.

@Peter87 Yes, i've edited it
closed account (EwCjE3v7)
Oh so each container has its own type of iterator?
closed account (EwCjE3v7)
anyone???? ^^^
http://www.cplusplus.com/reference/iterator/iterator/
That link is reference to the iterator header file.
Each container class uses the iterator header file in some way to hold an iterator or multiple iterators.

If you look at any of the container references on this site, they all list what types of iterators they have available.

Edit: I attempted reading the standard library vector header file provided by MinGW and I was unsuccessful in finding out where exactly the iterator type is defined. (There is a lot of includes used in MinGW's implementation of vector.)
Last edited on
I wondered if an interator was a type? Or is it a function?
An iterator is a type.

In the special cases where you can use a pointer, it's still a type, a pointer to an element.

Oh so each container has its own type of iterator?
Yes.

An iterator is used to traverse a data structure. Each data structure may be traversed differently. so the corresponding iterators will be different.
Topic archived. No new replies allowed.