Ticket #5697: iterator_facade.cpp.patch
File iterator_facade.cpp.patch, 3.0 KB (added by , 11 years ago) |
---|
-
D:/boost_1_47_0/libs/iterator/test/iterator_facade.
old new 7 7 #include <boost/iterator/iterator_facade.hpp> 8 8 #include <boost/iterator/new_iterator_tests.hpp> 9 9 10 #include <boost/call_traits.hpp> 11 #include <boost/type_traits/is_convertible.hpp> 12 #include <boost/utility/enable_if.hpp> 13 10 14 // This is a really, really limited test so far. All we're doing 11 15 // right now is checking that the postfix++ proxy for single-pass 12 16 // iterators works properly. … … 87 91 } 88 92 }; 89 93 94 template <class T> 95 struct wrapper 96 { 97 T m_x; 98 explicit wrapper(typename boost::call_traits<T>::param_type x) 99 : m_x(x) 100 { } 101 template <class U> 102 wrapper(const wrapper<U>& other, 103 typename boost::enable_if< boost::is_convertible<U,T> >::type* = 0) 104 : m_x(other.m_x) 105 { } 106 }; 107 108 struct iterator_with_proxy_reference 109 : boost::iterator_facade< 110 iterator_with_proxy_reference 111 , wrapper<int> 112 , boost::incrementable_traversal_tag 113 , wrapper<int&> 114 > 115 { 116 int& m_x; 117 explicit iterator_with_proxy_reference(int& x) 118 : m_x(x) 119 { } 120 121 void increment() 122 { } 123 wrapper<int&> dereference() const 124 { return wrapper<int&>(m_x); } 125 }; 126 90 127 template <class T, class U> 91 128 void same_type(U const&) 92 129 { BOOST_MPL_ASSERT((boost::is_same<T,U>)); } 93 130 94 131 int main() 95 132 { 96 int state = 0; 97 boost::readable_iterator_test(counter_iterator<int const&>(&state), 0); 98 state = 3; 99 boost::readable_iterator_test(counter_iterator<proxy>(&state), 3); 100 boost::writable_iterator_test(counter_iterator<proxy>(&state), 9, 7); 101 BOOST_TEST(state == 8); 133 { 134 int state = 0; 135 boost::readable_iterator_test(counter_iterator<int const&>(&state), 0); 136 state = 3; 137 boost::readable_iterator_test(counter_iterator<proxy>(&state), 3); 138 boost::writable_iterator_test(counter_iterator<proxy>(&state), 9, 7); 139 BOOST_TEST(state == 8); 140 } 102 141 103 // test for a fix to http://tinyurl.com/zuohe 104 // These two lines should be equivalent (and both compile) 105 input_iter p; 106 (*p).mutator(); 107 p->mutator(); 142 { 143 // test for a fix to http://tinyurl.com/zuohe 144 // These two lines should be equivalent (and both compile) 145 input_iter p; 146 (*p).mutator(); 147 p->mutator(); 108 148 109 same_type<input_iter::pointer>(p.operator->()); 110 149 same_type<input_iter::pointer>(p.operator->()); 150 } 151 152 { 153 int x = 0; 154 iterator_with_proxy_reference i(x); 155 BOOST_TEST(x == 0); 156 BOOST_TEST(i.m_x == 0); 157 ++(*i).m_x; 158 BOOST_TEST(x == 1); 159 BOOST_TEST(i.m_x == 1); 160 ++i->m_x; 161 BOOST_TEST(x == 2); 162 BOOST_TEST(i.m_x == 2); 163 } 164 111 165 return boost::report_errors(); 112 166 }