I have implemented the iterator_traits struct as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
template<typename Iter>
struct Estd::iterator_traits
{
using value_type = typename Iter::value_type;
using difference_type = typename Iter::difference_type;
/// pointer type
using pointer = typename Iter::pointer;
/// reference type
using reference = typename Iter::reference;
/// tag
using iterator_category =
typename Iter::iterator_category;
};
I have tried testing this with the following test code:
1 2 3 4 5
void test()
{
/// int
Estd::iterator_traits<vector<int>>::value_type i {5};
}
However, I get the following compilation error:
In instantiation of struct Estd::iterator_traits<vector<int>>
error: no type named 'iterator_category' in class std::vector<int>
However, in other contexts, I have tried accessing std::iterator_traits<Iter>::iterator_category and it works just fine.