//迭代器类
namespace detail_range
{
template <typename T>
class iterator
{
public:
using value_type = T;
using size_type = size_t;
private:
size_type cursor_;
const value_type step_;
value_type value_;
public:
iterator(size_type cur_start, value_type begin_val, value_type step_val)
:cursor_(cur_start)
, step_(step_val)
, value_(begin_val)
{
value_ += (step_*cursor_);
}
value_type operator*()const
{
return value_;
}
bool operator!=(const iterator&rhs)const
{
return (cursor_ != rhs.cursor_);
}
iterator& operator++(void)
{
value_ += step_;
++cursor_;
return (*this);
}
};
template<typename T>
class impl
{
public:
using value_type = T;
using reference = const value_type&;
using const_reference = const value_type&;
using iterator = const detail_range::iterator<value_type>;
C++11—迭代器类实现
最新推荐文章于 2024-04-19 09:24:38 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)