I noticed recently that our input_iterator_wrapper utility for writing
tests has the following post-increment operator:
void
operator++(int)
{
++*this;
}
That fails to meet the Cpp17InputIterator requirement that *r++ is
valid. This change makes it return a non-void proxy type that can be
deferenced to produce another proxy, which is convertible to the
value_type. The second proxy converts to const T& to ensure it can't be
written to.
* testsuite/util/testsuite_iterators.h:
(input_iterator_wrapper::operator++(int)): Return proxy object.
: public std::iterator<std::input_iterator_tag, typename remove_cv<T>::type,
std::ptrdiff_t, T*, T&>
{
+ struct post_inc_proxy
+ {
+ struct deref_proxy
+ {
+ T* ptr;
+ operator const T&() const { return *ptr; }
+ } p;
+
+ deref_proxy operator*() const { return p; }
+ };
+
protected:
input_iterator_wrapper() : ptr(0), SharedInfo(0)
{ }
return *this;
}
- void
+ post_inc_proxy
operator++(int)
{
+ post_inc_proxy tmp = { { ptr } };
++*this;
+ return tmp;
}
#if __cplusplus >= 201103L