正确的做法是将类型别名放入
iterator
而不是尝试部分专业化
std::iterator_traits
是的。
namespace Toolbox {
template <typename CharType>
class substring_container_adapter
{
public:
struct iterator // : public std::iterator<std::forward_iterator_tag, const CharType *> C++ 17 is very upset at this approach!
{
using iterator_category = forward_iterator_tag;
using value_type = const CharType *;
using reference = const CharType * &;
using pointer = const CharType * *;
using difference_type = std::ptrdiff_t;
// iterator constructor
iterator(value_type pszPosition, value_type pszDelimeters)
// ...
}
}
}
反对的主要原因
std::iterator
委员会不喜欢它给人的印象
Iterators
应该从中派生,因为不需要任何容器迭代器。您可以定义一个确切的替换。
namespace not_std {
template<class Category, class T, class Distance = ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator {
using iterator_category = Category;
using value_type = T;
using difference_type = Distance;
using pointer = Pointer;
using reference = Reference;
};
}