diff --git a/src/types.cc b/src/types.cc index 066b5ac..cde0c00 100644 --- a/src/types.cc +++ b/src/types.cc @@ -65,6 +65,9 @@ namespace pEp { free_stringpair(sp); } + + template<> + stringpair_t* stringpair_list_t::* const ListWrapper::Value = &stringpair_list_t::value; //////////////// diff --git a/src/wrapper.hh b/src/wrapper.hh index 1ef0819..ce2d71e 100644 --- a/src/wrapper.hh +++ b/src/wrapper.hh @@ -116,25 +116,38 @@ class ListWrapper : public Wrapper public: struct Trait; typedef Wrapper Base; - typedef ListWrapper iterator; // FIXME: different type necessary? - + typedef ListWrapper LW; + static Element T::* const Value; // to access the current value - using Base::Base; + // does not own the *value + class iterator + { + public: + iterator() = default; + + iterator operator++() { return (value ? value = value->next : value); } + Element operator*() { return value->*LW::Value; } + bool operator==(const iterator& other) const { return value == other.value; } + bool operator!=(const iterator& other) const { return value != other.value; } + + private: + iterator(T* _t) : value{_t} {} + T* value = nullptr; + friend class ListWrapper; + }; + + using Base::value; ListWrapper() : Base() {} - ListWrapper(const std::initializer_list& i); + ListWrapper(const std::initializer_list >& i); - iterator begin() { return value; } + iterator begin() { return iterator{value}; } iterator end() const { return iterator{}; } int size() const; bool empty() const; - // I am my own iterator - iterator operator++() { return (value ? value = value->next : value); } - Element operator*() { return value->*Value; } - void erase(const iterator& it); void clear(); void push_back(Element&&);