class template
<iterator>
std::iterator_traitstemplate <class Iterator> class iterator_traits;template <class T> class iterator_traits<T*>;template <class T> class iterator_traits<const T*>;
Iterator traits
Traits class defining properties of iterators.Standard algorithms determine certain properties of the iterators passed to them and the range they represent by using the members of the corresponding iterator_traits instantiation.
For every iterator type, a corresponding specialization of iterator_traits class template shall be defined, with at least the following member types defined:
void
.
The iterator_traits class template comes with a default definition that obtains these types from the iterator type itself (see below). It is also specialized for pointers (T*) and pointers to const (const T*).
Note that any custom class will have a valid instantiation of iterator_traits if it publicly inherits the base class std::iterator.
1
2
3
4
5
6
7
8
9
10
11
// iterator_traits example
#include <iostream> // std::cout
#include <iterator> // std::iterator_traits
#include <typeinfo> // typeid
int main() {
typedef std::iterator_traits<int*> traits;
if (typeid(traits::iterator_category)==typeid(std::random_access_iterator_tag))
std::cout << "int* is a random-access iterator";
return 0;
}
int* is a random-access iterator
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4