Provide a template to create STL-compliant forward iterators.
More...
Detailed Description
- Outline
-
-
- Purpose:
- Provide a template to create STL-compliant forward iterators.
-
- Classes:
-
- Canonical Header:
- bsl_iterator.h
- See also:
- Component bslstl_iterator, Component bslstl_bidirectionaliterator, Component bslstl_randomaccessiterator
-
- Description:
- This component provides an iterator adaptor that, given an implementation class defining a core set of iterator functionality, adapts it to provide an STL-compliant forward iterator interface. The set of requirements for a forward iterator is found in "Table 106: Forward iterator
requirements", under the tag "[forward.iterators]". (Note that this reference is sourced in N3092, a C++0x working paper; the actual table number may vary in the actual standard.) Include bsl_iterator.h to use this component.
-
- Usage:
- Given the following "iterator-like" implementation class:
template <class T>
class my_IteratorImp {
public:
my_IteratorImp();
my_IteratorImp(const my_IteratorImp&);
~my_IteratorImp();
my_IteratorImp& operator=(const my_IteratorImp&);
void operator++();
T& operator*() const;
};
template <class T>
bool operator==(const my_IteratorImp<T>& lhs,
const my_IteratorImp<T>& rhs);
simply add the following two typedef
s to any container class that provides my_IteratorImp<T>
access, and the container will have STL-compliant forward iterators: Note that the implementation for const_iterator
is my_IteratorImp<T>
and not my_IteratorImp<const T>
, rather the const
is added to the return value of operator*
by way of conversion to the first template argument.