I
Ioannis Vranos
I am reading TC++PL3 and on page 552 it is mentioned:
"The related types of an iterator are described by a small set of
declarations in an iterator_traits template class:
template <class Iter> struct iterator_traits {
typedef typename Iter::iterator_category iterator_category; //19.2.3
typedef typename Iter::value_type value_type; // type of element
typedef typename Iter::difference_type difference_type;
typedef typename Iter:ointer pointer; //return type of operator->()
typedef typename Iter::reference reference; //return type of operator*()
};"
How can we use Iter.operator->() to get an iterator_traits<Iter>::
pointer? Let's assume vector<int> as an example and we want to get a
pointer to the first element of the sequence using operator->():
#include <vector>
#include <iostream>
#include <iterator>
int main()
{
using namespace std;
vector<int> vec(10);
iterator_traits<vector<int>::iterator>:ointer p= ???
}
"The related types of an iterator are described by a small set of
declarations in an iterator_traits template class:
template <class Iter> struct iterator_traits {
typedef typename Iter::iterator_category iterator_category; //19.2.3
typedef typename Iter::value_type value_type; // type of element
typedef typename Iter::difference_type difference_type;
typedef typename Iter:ointer pointer; //return type of operator->()
typedef typename Iter::reference reference; //return type of operator*()
};"
How can we use Iter.operator->() to get an iterator_traits<Iter>::
pointer? Let's assume vector<int> as an example and we want to get a
pointer to the first element of the sequence using operator->():
#include <vector>
#include <iostream>
#include <iterator>
int main()
{
using namespace std;
vector<int> vec(10);
iterator_traits<vector<int>::iterator>:ointer p= ???
}