One of the problems Deducing this solves is duplication by making member functions cvref aware of the cvref-ness of the object the function is being called on. By declaring Alias templates (Template Typdefs) and returning them in the member functions rather than just returning auto are we not forced to have two iterator objects?
template <typename T>
struct const_list_iterator{
typedef const T& reference;
typedef const T* pointer;
reference operator*() const{/***/}
pointer operator ->() const{/***/}
};
and
template <typename T >
struct list_iterator{
typedef T& reference;
typedef T* pointer;
reference operator*(){/***/}
pointer operator ->(){/***/}
};
However, with Deducing this if the return type is auto can we simply have a single iterator object?
template <typename T>
struct list_iterator
template <typename itself>
auto operator*(this itself&& self){/***/}
template <typename itself>
auto operator->(this itself&& self){/***/}
};
Which we can use as below:
template <typename T>
struct list{
using iterator = list_iterator<T>;
auto begin() -> iterator {
iterator(node -> next);
}
auto begin() const -> iterator{
iterator(node -> next)
}
};
So, will using typedefs force us to duplicate iterator objects?
begin/endoverloads?value_typeof the collection, you could have made your "const iterator" type use aconst value_type.const list<T> list:list.begin()returns alist_iterator<T>, which I then dereference with*to access the first list element and modify it. The const version ofbegin()needs to return alist_iterator<const T>.