iterator: add constant_iterator

This commit is contained in:
Danny Robson 2019-03-17 23:32:15 +11:00
parent 28e0a1afea
commit cb9e5a74b4

View File

@ -804,4 +804,49 @@ namespace cruft {
private:
IteratorT m_cursor;
};
}
///////////////////////////////////////////////////////////////////////////
namespace iterator {
template <typename ValueT>
class constant {
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = ValueT;
using difference_type = std::size_t;
using pointer = value_type*;
using reference = value_type&;
constant () = delete;
constant (ValueT &&_value) noexcept
: m_value (std::move (_value))
{ ; }
constant (ValueT const &_value)
: m_value (_value)
{ ; }
constant (constant const &) = default;
constant& operator= (constant const &) = default;
constant (constant &&) = default;
constant& operator= (constant &&) = default;
ValueT const& operator* () const& { return m_value; }
ValueT & operator* () & { return m_value; }
ValueT const* operator-> () const & { return &m_value; }
ValueT * operator-> () & { return &m_value; }
constant& operator++ ( ) { return *this; }
constant& operator++ (int) { return *this; }
constant& operator-- ( ) { return *this; }
constant& operator-- (int) { return *this; }
private:
ValueT m_value;
};
}
};