Commit b8aebbc0 authored by neverlord's avatar neverlord

std::iterator compliance

parent 7fd6146d
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef TYPE_VALUE_PAIR_HPP #ifndef TYPE_VALUE_PAIR_HPP
#define TYPE_VALUE_PAIR_HPP #define TYPE_VALUE_PAIR_HPP
#include <cstddef>
#include "cppa/uniform_type_info.hpp" #include "cppa/uniform_type_info.hpp"
namespace cppa { namespace cppa {
...@@ -44,17 +46,31 @@ class type_value_pair_const_iterator ...@@ -44,17 +46,31 @@ class type_value_pair_const_iterator
public: public:
typedef type_value_pair const value_type;
typedef std::ptrdiff_t difference_type;
typedef type_value_pair const* pointer;
typedef type_value_pair const& reference;
typedef std::bidirectional_iterator_tag iterator_category;
constexpr type_value_pair_const_iterator() : iter(nullptr) { }
type_value_pair_const_iterator(type_value_pair const* i) : iter(i) { } type_value_pair_const_iterator(type_value_pair const* i) : iter(i) { }
type_value_pair_const_iterator(type_value_pair_const_iterator const&) = default; type_value_pair_const_iterator(type_value_pair_const_iterator const&)
= default;
type_value_pair_const_iterator&
operator=(type_value_pair_const_iterator const&) = default;
inline uniform_type_info const* type() const { return iter->first; } inline uniform_type_info const* type() const { return iter->first; }
inline void const* value() const { return iter->second; } inline void const* value() const { return iter->second; }
inline decltype(iter) operator->() { return iter; } inline decltype(iter) base() const { return iter; }
inline decltype(iter) operator->() const { return iter; }
inline decltype(*iter) operator*() { return *iter; } inline decltype(*iter) operator*() const { return *iter; }
inline type_value_pair_const_iterator& operator++() inline type_value_pair_const_iterator& operator++()
{ {
...@@ -62,29 +78,45 @@ class type_value_pair_const_iterator ...@@ -62,29 +78,45 @@ class type_value_pair_const_iterator
return *this; return *this;
} }
inline type_value_pair_const_iterator& operator--() inline type_value_pair_const_iterator operator++(int)
{ {
--iter; type_value_pair_const_iterator tmp{*this};
return *this; ++iter;
return tmp;
} }
inline type_value_pair_const_iterator operator+(size_t offset) inline type_value_pair_const_iterator& operator--()
{ {
return iter + offset; --iter;
return *this;
} }
inline bool operator==(type_value_pair_const_iterator const& other) const inline type_value_pair_const_iterator operator--(int)
{ {
return iter == other.iter; type_value_pair_const_iterator tmp{*this};
--iter;
return tmp;
} }
inline bool operator!=(type_value_pair_const_iterator const& other) const inline type_value_pair_const_iterator operator+(size_t offset)
{ {
return iter != other.iter; return iter + offset;
} }
}; };
inline bool operator==(type_value_pair_const_iterator const& lhs,
type_value_pair_const_iterator const& rhs)
{
return lhs.base() == rhs.base();
}
inline bool operator!=(type_value_pair_const_iterator const& lhs,
type_value_pair_const_iterator const& rhs)
{
return !(lhs == rhs);
}
} // namespace cppa } // namespace cppa
#endif // TYPE_VALUE_PAIR_HPP #endif // TYPE_VALUE_PAIR_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment