From 0237e49a17ec058082576ad135820b13ce3e9d66 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 13 Sep 2006 22:24:14 +0000 Subject: [PATCH] fix for http://tinyurl.com/zuohe [SVN r35101] --- include/boost/iterator/iterator_facade.hpp | 8 ++--- test/iterator_facade.cpp | 37 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/include/boost/iterator/iterator_facade.hpp b/include/boost/iterator/iterator_facade.hpp index 462bd8b..0e494fe 100644 --- a/include/boost/iterator/iterator_facade.hpp +++ b/include/boost/iterator/iterator_facade.hpp @@ -293,17 +293,17 @@ namespace boost // operator->() needs special support for input iterators to strictly meet the // standard's requirements. If *i is not a reference type, we must still - // produce a (constant) lvalue to which a pointer can be formed. We do that by + // produce a lvalue to which a pointer can be formed. We do that by // returning an instantiation of this special proxy class template. template struct operator_arrow_proxy { operator_arrow_proxy(T const* px) : m_value(*px) {} - const T* operator->() const { return &m_value; } + T* operator->() const { return &m_value; } // This function is needed for MWCW and BCC, which won't call operator-> // again automatically per 13.3.1.2 para 8 - operator const T*() const { return &m_value; } - T m_value; + operator T*() const { return &m_value; } + mutable T m_value; }; // A metafunction that gets the result type for operator->. Also diff --git a/test/iterator_facade.cpp b/test/iterator_facade.cpp index 871c196..cb8ff62 100755 --- a/test/iterator_facade.cpp +++ b/test/iterator_facade.cpp @@ -56,7 +56,35 @@ struct proxy int& state; }; - + +struct value { int x; }; + +struct input_iter + : boost::iterator_facade< + input_iter + , value + , boost::single_pass_traversal_tag + , value + > +{ + public: + input_iter() {} + + void increment() + { + } + value + dereference() const + { + return value(); + } + + bool equal(input_iter const& y) const + { + return false; + } +}; + int main() { int state = 0; @@ -65,5 +93,12 @@ int main() boost::readable_iterator_test(counter_iterator(&state), 3); boost::writable_iterator_test(counter_iterator(&state), 9, 7); BOOST_ASSERT(state == 8); + + // test for a fix to http://tinyurl.com/zuohe + // These two lines should be equivalent (and both compile) + input_iter p; + (*p).x = 2; + p->x = 2; + return 0; }