2005-08-27 10:22:04 +00:00
|
|
|
#ifndef YASLI_FILL_ITERATOR_H_
|
|
|
|
#define YASLI_FILL_ITERATOR_H_
|
|
|
|
|
2006-10-17 19:59:11 +00:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
2005-08-27 10:22:04 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
namespace yasli_nstd
|
|
|
|
{
|
|
|
|
template <class T>
|
2006-06-19 12:39:09 +00:00
|
|
|
class fill_iterator_base
|
2005-08-27 10:22:04 +00:00
|
|
|
: public std::iterator<
|
|
|
|
std::random_access_iterator_tag,
|
2006-03-08 17:07:20 +00:00
|
|
|
T,
|
|
|
|
ptrdiff_t,
|
|
|
|
T*,
|
|
|
|
T&>
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
2006-06-19 12:39:09 +00:00
|
|
|
class fill_iterator_base<T&>
|
2005-08-27 10:22:04 +00:00
|
|
|
: public std::iterator<
|
|
|
|
std::random_access_iterator_tag,
|
2006-03-08 17:07:20 +00:00
|
|
|
T,
|
|
|
|
ptrdiff_t,
|
|
|
|
T*,
|
|
|
|
T&>
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class fill_iterator : public fill_iterator_base<T>
|
2006-03-08 17:07:20 +00:00
|
|
|
{
|
2005-08-27 10:22:04 +00:00
|
|
|
T value_;
|
|
|
|
/*difference_type*/ ptrdiff_t count_;//////////////////////////////////
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
typedef typename fill_iterator_base<T>::pointer pointer;
|
2006-03-08 17:07:20 +00:00
|
|
|
typedef typename fill_iterator_base<T>::reference reference;
|
|
|
|
//typedef iterator_type;
|
|
|
|
|
|
|
|
fill_iterator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit fill_iterator(reference value, difference_type count = 0)
|
|
|
|
: value_(value), count_(count)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class U>
|
2006-06-19 12:39:09 +00:00
|
|
|
fill_iterator(const fill_iterator<U>& rhs)
|
2006-03-08 17:07:20 +00:00
|
|
|
: value_(rhs.value_), count_(rhs.count_)
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
2006-03-08 17:07:20 +00:00
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
reference operator*() const
|
|
|
|
{
|
|
|
|
return value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
pointer operator->() const
|
|
|
|
{
|
|
|
|
return &**this;
|
|
|
|
}
|
|
|
|
|
|
|
|
fill_iterator& operator++()
|
|
|
|
{
|
2005-08-27 10:22:04 +00:00
|
|
|
++count_;
|
2006-03-08 17:07:20 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator operator++(int)
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator it(*this);
|
2005-08-27 10:22:04 +00:00
|
|
|
++*this;
|
2006-03-08 17:07:20 +00:00
|
|
|
return it;
|
2005-08-27 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator& operator--()
|
|
|
|
{
|
2005-08-27 10:22:04 +00:00
|
|
|
--count_;
|
2006-03-08 17:07:20 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator operator--(int)
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator it(*this);
|
2005-08-27 10:22:04 +00:00
|
|
|
--*this;
|
2006-03-08 17:07:20 +00:00
|
|
|
return it;
|
2005-08-27 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator& operator+=(difference_type d)
|
|
|
|
{
|
|
|
|
count_ += d;
|
|
|
|
return *this;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator operator+(difference_type d) const
|
|
|
|
{
|
|
|
|
return fill_iterator(*this) += d;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator& operator-=(difference_type d)
|
|
|
|
{
|
|
|
|
count_ -= d;
|
|
|
|
return *this;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
fill_iterator operator-(difference_type d) const
|
|
|
|
{
|
|
|
|
return fill_iterator(*this) -= d;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
|
|
|
difference_type operator-(const fill_iterator<T>& rhs) const
|
|
|
|
{
|
2006-03-08 17:07:20 +00:00
|
|
|
return count_ - rhs.count_;
|
2005-08-27 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 17:07:20 +00:00
|
|
|
reference operator[](difference_type) const
|
|
|
|
{
|
|
|
|
return **this;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
|
|
|
template <class T2>
|
|
|
|
bool operator==(const fill_iterator<T2>& rhs) const
|
2006-03-08 17:07:20 +00:00
|
|
|
{
|
|
|
|
return count_ == rhs.count_;
|
2005-08-27 10:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T, class D>
|
|
|
|
inline fill_iterator<T> operator+(D lhs, const fill_iterator<T>& rhs)
|
|
|
|
{
|
2006-03-08 17:07:20 +00:00
|
|
|
return rhs + lhs;
|
|
|
|
}
|
2005-08-27 10:22:04 +00:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline bool operator!=(
|
|
|
|
const fill_iterator<T>& lhs,
|
2006-06-19 12:39:09 +00:00
|
|
|
const fill_iterator<T>& rhs)
|
2006-03-08 17:07:20 +00:00
|
|
|
{ // test for fill_iterator inequality
|
2005-08-27 10:22:04 +00:00
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline bool operator<(
|
|
|
|
const fill_iterator<T>& lhs,
|
2006-06-19 12:39:09 +00:00
|
|
|
const fill_iterator<T>& rhs)
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
|
|
|
return lhs.count_ < rhs.count_;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline bool operator>(
|
|
|
|
const fill_iterator<T>& lhs,
|
2006-03-08 17:07:20 +00:00
|
|
|
const fill_iterator<T>& rhs)
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
|
|
|
return rhs < lhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline bool operator<=(
|
|
|
|
const fill_iterator<T>& lhs,
|
2006-03-08 17:07:20 +00:00
|
|
|
const fill_iterator<T>& rhs)
|
2005-08-27 10:22:04 +00:00
|
|
|
{
|
|
|
|
return !(rhs < lhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
inline bool operator>=(
|
|
|
|
const fill_iterator<T>& lhs,
|
|
|
|
const fill_iterator<T>& rhs)
|
|
|
|
{
|
|
|
|
return !(lhs < rhs);
|
|
|
|
}
|
|
|
|
} // namespace yasli_nstd
|
|
|
|
|
|
|
|
#endif
|