| Author: | David Abrahams, Jeremy Siek, Thomas Witt |
|---|---|
| Contact: | dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de |
| Organization: | Boost Consulting, Indiana University Open Systems Lab, University of Hanover Institute for Transport Railway Operation and Construction |
| Date: | 2003-09-14 |
| Copyright: | Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved |
| abstract: |
|---|
The counting iterator adaptor implements dereference by returning a reference to the base object. The other operations are implemented by the base m_iterator, as per the inheritance from iterator_adaptor.
template <
class Incrementable
, unsigned Access = use_default_access
, class Traversal = use_default
, class Difference = use_default
>
class counting_iterator
: public iterator_adaptor<
counting_iterator<Incrementable, Access, Traversal, Difference>
, Incrementable
, Incrementable
, Access
, /* see details for traversal category */
, Incrementable const&
, Incrementable const*
, /* distance = Difference or a signed integral type */>
{
friend class iterator_core_access;
public:
counting_iterator();
counting_iterator(counting_iterator const& rhs);
counting_iterator(Incrementable x);
private:
typename counting_iterator::reference dereference() const
{
return this->base_reference();
}
};
The Incrementable type must be Default Constructible, Copy Constructible, and Assignable. The default distance is an implementation defined signed integegral type.
The resulting counting_iterator models Readable Lvalue Iterator.
Furthermore, if you wish to create a counting iterator that is a Forward Traversal Iterator, then the following expressions must be valid:
Incrementable i, j; ++i // pre-increment i == j // operator equal
If you wish to create a counting iterator that is a Bidirectional Traversal Iterator, then pre-decrement is also required:
--i
If you wish to create a counting iterator that is a Random Access Traversal Iterator, then these additional expressions are also required:
counting_iterator::difference_type n; i += n n = i - j i < j
counting_iterator();
| Returns: | A default constructed instance of counting_iterator. |
|---|
counting_iterator(counting_iterator const& rhs);
| Returns: | An instance of counting_iterator that is a copy of rhs. |
|---|
counting_iterator(Incrementable x);
| Returns: | An instance of counting_iterator with its base object copy constructed from x. |
|---|