beautypg.com

Iterator requirements – HP Integrity NonStop H-Series User Manual

Page 215

background image

the_allocator.construct(current_end,*start); // 3

// Now lets remove duplicates using a standard algorithm
std::unique(begin(),end());
}

} // End of my_namespace

//1 The allocator parameter is copied into a protected member of the container. This private

copy can then be used for all subsequent storage management.

//2 An initial buffer is allocated using the allocator's allocate function.

//3 The contents of the buffer are initialized using the values from the iterator range supplied to

the constructor by the start and finish parameters. The construct function constructs an
object at a particular location. In this case the location is at an index in the container's
buffer.

Iterator Requirements

Every container must define an iterator type. Iterators allow algorithms to iterate over the
container's contents. Although iterators can range from simple to very complex, it is the iterator
category
, not the complexity, that most affects an algorithm. The iterator category describes
capabilities of the iterator, such as which direction it can traverse. The "Tips and Techniques"
section below, and the iterator entries in the reference provides additional information about
iterator categories.

The example in the previous section shows the implementation of a container that uses a simple
pointer. A simple pointer is actually an example of the most powerful type of iterator: a random
access iterator. If an iterator supports random access, we can add to or subtract from it as easily
as we can increment it.

Some iterators have much less capability. For example , consider an iterator attached to a
singly-linked list. Since each node in the list has links leading forward only, a na_ve iterator can
advance through the container in only one direction. An iterator with this limitation falls into the
category of forward iterator.

Certain member functions such as begin()and end() produce iterators for a container. A
container's description should always describe the category of iterator that its member functions
produce. That way, a user of the container can see immediately which algorithms can operate
successfully on the container.

This manual is related to the following products: