Example
This example uses the value_type iterator tag function in order to declare a temporary variable of an iterator's value type.
template
inline void __iter_swap(ForwardIterator1 a, ForwardIterator2 b, ValueType*) {
T tmp = *a;
*a = *b;
*b = tmp;
}
template
inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b) {
__iter_swap(a, b, value_type (a));
}
Notes
[1] Note that distance_type is not defined for Output Iterators or for Trivial Iterators. In the case of Output Iterators, this is because an Output Iterator does not have a value type: it is not possible to dereference an Output Iterator and obtain a value. In the case of Trivial Iterators, this is because the concept was introduced only for conceptual clarity, in order to separate the axioms related to an object that refers to another object from those related to iteration over a range. In fact, the STL does not define any types that are Trivial Iterators. Although built-in C pointers may be Trivial Iterators, the C type system does not allow a distinction between pointers that are Trivial Iterators and pointers that are Random Access Iterators into C arrays. Consequently, there is no Trivial Iterator category tag or iterator base.
[2] The iterator_traits class relies on a C++ feature known as partial specialization . Many of today's compilers don't implement the complete standard; in particular, many compilers do not support partial specialization. If your compiler does not support partial specialization, then you will not be able to use iterator_traits , and you will have to continue using the functions iterator_category , distance_type , and value_type . This is one reason that those functions have not yet been removed.
See also
The Iterator Tags overview, iterator_traits , iterator_category , distance_type , output_iterator_tag , input_iterator_tag , forward_iterator_tag , bidirectional_iterator_tag , random_access_iterator_tag
Category: iterators
Component type: type
Description
Input_iterator_tag is an empty class: it has no member functions, member variables, or nested types. It is used solely as a "tag": a representation of the Input Iterator concept within the C++ type system. Specifically, it is used as a return value for the function iterator_category . Iterator_category takes a single argument, an iterator, and returns an object whose type depends on the iterator's category. Iterator_category 's return value is of type input_iterator_tag if its argument is an Input Iterator.
Example
See iterator_category
Definition
Defined in the standard header iterator, and in the nonstandard backward-compatibility header iterator.h.
Template parameters
None.
Model of
Assignable
Type requirements
None.
Public base classes
None.
Members
None.
New Members
None.
See also
iterator_category , Iterator Tags, iterator_traits , output_iterator_tag , forward_iterator_tag , bidirectional_iterator_tag , random_access_iterator_tag
Category: iterators
Component type: type
Description
Output_iterator_tag is an empty class: it has no member functions, member variables, or nested types. It is used solely as a "tag": a representation of the Output Iterator concept within the C++ type system. Specifically, it is used as a return value for the function iterator_category . Iterator_category takes a single argument, an iterator, and returns an object whose type depends on the iterator's category. Iterator_category 's return value is of type output_iterator_tag if its argument is an Output Iterator.
Example
See iterator_category
Definition
Defined in the standard header iterator, and in the nonstandard backward-compatibility header iterator.h.
Template parameters
None.
Model of
Assignable
Type requirements
None.
Public base classes
None.
Members
None.
New Members
None.
See also
iterator_category , Iterator Tags, iterator_traits , input_iterator_tag , forward_iterator_tag , bidirectional_iterator_tag , random_access_iterator_tag
Category: iterators
Component type: type
Description
Forward_iterator_tag is an empty class: it has no member functions, member variables, or nested types. It is used solely as a "tag": a representation of the Forward Iterator concept within the C++ type system. Specifically, it is used as a return value for the function iterator_category . Iterator_category takes a single argument, an iterator, and returns an object whose type depends on the iterator's category. Iterator_category 's return value is of type forward_iterator_tag if its argument is a Forward Iterator.
Example
See iterator_category
Definition
Defined in the standard header iterator, and in the nonstandard backward-compatibility header iterator.h.
Template parameters
None.
Model of
Assignable
Type requirements
None.
Public base classes
None.
Members
None.
New Members
None.
See also
iterator_category , Iterator Tags, iterator_traits , output_iterator_tag , input_iterator_tag , bidirectional_iterator_tag , random_access_iterator_tag
bidirectional_iterator_tag
Category: iterators
Component type: type
Description
Bidirectional_iterator_tag is an empty class: it has no member functions, member variables, or nested types. It is used solely as a "tag": a representation of the Bidirectional Iterator concept within the C++ type system. Specifically, it is used as a return value for the function iterator_category . Iterator_category takes a single argument, an iterator, and returns an object whose type depends on the iterator's category. Iterator_category 's return value is of type bidirectional_iterator_tag if its argument is a Bidirectional Iterator.
Читать дальше