Boost C++ 库

……世界上最受推崇且设计最专业的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu,《C++ 编码规范

迭代器特性 - Boost C++ 函数库

迭代器特性

作者 David Abrahams
联系方式 dave@boost-consulting.com
组织 Boost Consulting
版权 Copyright David Abrahams 2004。
摘要头文件<boost/iterator/iterator_traits.hpp>提供使用 MPL 兼容的 元函数 访问迭代器相关类型的功能。

概述

std::iterator_traits提供对任何迭代器的五个相关类型的访问:其value_type, reference, pointer, iterator_categorydifference_type. 不幸的是,这种“多值” traits 模板在元编程上下文中可能难以使用。<boost/iterator/iterator_traits.hpp>使用标准 元函数 提供对这些类型的访问。

总结

头文件<boost/iterator/iterator_traits.hpp>:

template <class Iterator>
struct iterator_value
{
    typedef typename
      std::iterator_traits<Iterator>::value_type
    type;
};

template <class Iterator>
struct iterator_reference
{
    typedef typename
      std::iterator_traits<Iterator>::reference
    type;
};


template <class Iterator>
struct iterator_pointer
{
    typedef typename
      std::iterator_traits<Iterator>::pointer
    type;
};

template <class Iterator>
struct iterator_difference
{
    typedef typename
      detail::iterator_traits<Iterator>::difference_type
    type;
};

template <class Iterator>
struct iterator_category
{
    typedef typename
      detail::iterator_traits<Iterator>::iterator_category
    type;
};