iterator: add 'iota' pseudo-container

This commit is contained in:
Danny Robson 2019-01-20 17:57:38 +11:00
parent abb9d4c3aa
commit f7c477b163

View File

@ -220,6 +220,44 @@ namespace cruft {
}
///////////////////////////////////////////////////////////////////////////
template <typename ValueT = std::size_t>
class iota {
public:
using value_type = ValueT;
iota (ValueT _total)
: m_total (_total)
{ ; }
struct iterator {
iterator (ValueT _value)
: m_value (_value)
{ ; }
ValueT const* operator-> () const noexcept { return &m_value; }
ValueT const& operator* () const noexcept { return m_value; }
iterator& operator++ () noexcept { ++m_value; return *this; }
bool operator!= (iterator const &rhs) const noexcept { return m_value != rhs.m_value; }
ValueT m_value;
};
iterator begin (void) const { return iterator( 0); }
iterator end (void) const { return iterator(m_total); }
ValueT size (void) const { return m_total; }
private:
ValueT m_total;
};
template <typename ValueT>
iota (ValueT) -> iota<ValueT>;
///////////////////////////////////////////////////////////////////////////
template <typename ContainerT>
class indices {