| 作者 | 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_category和difference_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;
};