--- D:/boost_1_47_0/libs/iterator/test/iterator_facade.old.cpp Tue Mar 29 14:17:11 2011 +++ D:/boost_1_47_0/libs/iterator/test/iterator_facade.new.cpp Sat Jul 16 20:32:34 2011 @@ -7,6 +7,10 @@ #include #include +#include +#include +#include + // This is a really, really limited test so far. All we're doing // right now is checking that the postfix++ proxy for single-pass // iterators works properly. @@ -87,26 +91,76 @@ } }; +template +struct wrapper +{ + T m_x; + explicit wrapper(typename boost::call_traits::param_type x) + : m_x(x) + { } + template + wrapper(const wrapper& other, + typename boost::enable_if< boost::is_convertible >::type* = 0) + : m_x(other.m_x) + { } +}; + +struct iterator_with_proxy_reference + : boost::iterator_facade< + iterator_with_proxy_reference + , wrapper + , boost::incrementable_traversal_tag + , wrapper + > +{ + int& m_x; + explicit iterator_with_proxy_reference(int& x) + : m_x(x) + { } + + void increment() + { } + wrapper dereference() const + { return wrapper(m_x); } +}; + template void same_type(U const&) { BOOST_MPL_ASSERT((boost::is_same)); } int main() { - int state = 0; - boost::readable_iterator_test(counter_iterator(&state), 0); - state = 3; - boost::readable_iterator_test(counter_iterator(&state), 3); - boost::writable_iterator_test(counter_iterator(&state), 9, 7); - BOOST_TEST(state == 8); + { + int state = 0; + boost::readable_iterator_test(counter_iterator(&state), 0); + state = 3; + boost::readable_iterator_test(counter_iterator(&state), 3); + boost::writable_iterator_test(counter_iterator(&state), 9, 7); + BOOST_TEST(state == 8); + } - // test for a fix to http://tinyurl.com/zuohe - // These two lines should be equivalent (and both compile) - input_iter p; - (*p).mutator(); - p->mutator(); + { + // test for a fix to http://tinyurl.com/zuohe + // These two lines should be equivalent (and both compile) + input_iter p; + (*p).mutator(); + p->mutator(); - same_type(p.operator->()); - + same_type(p.operator->()); + } + + { + int x = 0; + iterator_with_proxy_reference i(x); + BOOST_TEST(x == 0); + BOOST_TEST(i.m_x == 0); + ++(*i).m_x; + BOOST_TEST(x == 1); + BOOST_TEST(i.m_x == 1); + ++i->m_x; + BOOST_TEST(x == 2); + BOOST_TEST(i.m_x == 2); + } + return boost::report_errors(); }