What are the typical use cases of an iterator_trait

最后都变了- 提交于 2019-12-03 09:47:19

Pointers into an array can be used as random access iterators.

There needs to be some consistent way to get these types both for pointers (which obviously can't have the types declared as nested types, since only classes can have nested types) and for class-type iterators. The traits class template provides this consistent way.

The iterator_traits class template is specialized for pointers like so:

template <typename T>
struct iterator_traits<T*>
{
    typedef std::random_access_iterator_tag iterator_category;
    typedef T                               value_type;
    typedef T*                              pointer;
    typedef T&                              reference;
    typedef std::ptrdiff_t                  difference_type;
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!