Espacios de nombres
Variantes
Acciones

std::iterator_traits

De cppreference.com
< cpp‎ | iterator

 
 
Biblioteca Iterator
Primitivas iterador
Original:
Iterator primitives
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
iterator_traits
input_iterator_tag
output_iterator_tag
forward_iterator_tag
bidirectional_iterator_tag
random_access_iterator_tag
iterator
Adaptadores iterador
Original:
Iterator adaptors
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reverse_iterator
Iteradores Stream
Original:
Stream iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
istream_iterator
ostream_iterator
istreambuf_iterator
ostreambuf_iterator
Operaciones iterador
Original:
Iterator operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
advance
distance
prev(C++11)
next(C++11)
Rango de acceso
Original:
Range access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
begin(C++11)
end(C++11)
 
Defined in header <iterator>
template< class Iterator>
struct iterator_traits;
template< class T >
struct iterator_traits<T*>;
template< class T >
struct iterator_traits<const T*>;
std::iterator_traits es la clase rasgo tipo que proporciona una interfaz uniforme para las propiedades de los tipos de iterador. Esto hace que sea posible implementar algoritmos sólo en términos de iteradores .
Original:
std::iterator_traits is the type trait class that provides uniform interface to the properties of iterator types. This makes it possible to implement algorithms only in terms of iterators.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Tipos de miembros

Miembro de tipo
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
difference_type Iterator::difference_type
value_type Iterator::value_type
pointer Iterator::pointer
reference Iterator::reference
iterator_category Iterator::iterator_category

[editar] Especializaciones

Este rasgo tipo puede ser especializada para proporcionado por el usuario tipos que pueden ser utilizados como iteradores. La biblioteca estándar proporciona dos especializaciones parciales de tipos de puntero T *, lo que hace posible el uso de todos los algoritmos basados ​​iterador con punteros primas .
Original:
This type trait may be specialized for user-provided types that may be used as iterators. The standard library provides two partial specializations for pointer types T*, which makes it possible to use all iterator-based algorithms with raw pointers.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] T * Tipos de especialización miembros

Miembro de tipo
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
difference_type std::ptrdiff_t
value_type T
pointer T*
reference T&
iterator_category std::random_access_iterator_tag

[editar] const T * tipos de miembro de especialización

Miembro de tipo
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
difference_type std::ptrdiff_t
value_type T
pointer const T*
reference const T&
iterator_category std::random_access_iterator_tag

[editar] Ejemplo

de propósito general reverse () de ejecución de iteradores bidireccionales
Original:
general-purpose reverse() implementation for bidirectional iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <iostream>
#include <iterator>
#include <vector>
#include <list>
 
template<class BDIter>
void my_reverse(BDIter first, BDIter last)
{
    typename std::iterator_traits<BDIter>::difference_type n = std::distance(first, last);
    --n;
    while(n > 0) {
        typename std::iterator_traits<BDIter>::value_type tmp = *first;
        *first++ = *--last;
        *last = tmp;
        n -= 2;
    }
}
 
int main()
{
    std::vector<int> v{1,2,3,4,5};
    my_reverse(v.begin(), v.end());
    for(int n : v)
        std::cout << n << ' ';
    std::cout << '\n';
 
    std::list<int> l{1,2,3,4,5};
    my_reverse(l.begin(), l.end());
    for(auto n : l)
        std::cout << n << ' ';
    std::cout << '\n';
 
//    std::istreambuf_iterator<char> i1(std::cin), i2;
//    my_reverse(i1, i2); // compilation error
 
}

Output:

5 4 3 2 1
5 4 3 2 1

[editar] Ver también

el iterador de base
Original:
the basic iterator
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(clase de plantilla) [edit]
tipos de clase vacíos para indicar categorías iterador
Original:
empty class types used to indicate iterator categories
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(clase) [edit]