Type primitive
Determine the type of value an iterator points to.
#include <iterator>
template <class T, class Distance> inline T* value_type (const input_iterator<T, Distance>&) template <class T, class Distance> inline T* value_type (const forward_iterator<T, Distance>&) template <class T, class Distance> inline T* value_type (const bidirectional_iterator<T, Distance>&) template <class T, class Distance> inline T* value_type (const random_access_iterator<T, Distance>&) template <class T> inline T* value_type (const T*)
The value_type function template returns a pointer to a default value of the type pointed to by an iterator. Five overloaded versions of this function template handle the four basic iterator types and simple arrays. Each of the first four take an iterator of a specific type, and return the value used to instantiate the iterator. The fifth version takes and returns a T* in order to handle the case when an iterator is a simple pointer.
This family of function templates can be used to extract a value type from an iterator and subsequently use that type to create a local variable. Typically the value_type functions are used like this:
template <class Iterator> void foo(Iterator first, Iterator last) { __foo(begin,end,value_type(first)); } template <class Iterator, class T> void __foo(Iterator first, Iterator last, T*> { T temp = *first; _ }
The auxiliary function __foo extracts a usable value type from the iterator and then puts the type to work.
Other iterator primitives: distance_type, iterator_category, distance, advance