
Hello, I'm a little behind the times and am trying to port my old iterator_adapters code to use the new library (1.32). We have a class which is little more than a wrapper around a vector<shared_ptr<T> >, and I am having a heck of a time with setting its typedef for reverse_iterator and const_reverse_iterator. I just can't get const_reverse_iterator to do assignment and comparison with reverse_iterator. I've tried to make indirect_iterators out of the native reverse iterators, using boost::reverse_iterators of indirect_iterators, and a number of more complicated combinations of the 3. No matter which I try I get errors about the const_reverse_iterator not playing nicely with the reverse_iterator. I think I've read everything on the list archives about indirect_iterator, but perhaps I missed something. I'm going to try my code on g++ (currently using VC 7.1) and then work on a complete example, but I thought I'd throw this out and see if someone can quickly answer it. Thanks, Tom

Thomas Matelich <matelich@gmail.com> writes:
Hello,
I'm a little behind the times and am trying to port my old iterator_adapters code to use the new library (1.32). We have a class which is little more than a wrapper around a vector<shared_ptr<T> >, and I am having a heck of a time with setting its typedef for reverse_iterator and const_reverse_iterator. I just can't get const_reverse_iterator to do assignment and comparison with reverse_iterator.
I've tried to make indirect_iterators out of the native reverse iterators,
That almost certainly won't work, because the native reverse_iterator usually won't play nicely with the native const_reverse_iterator.
using boost::reverse_iterators of indirect_iterators
What happens when you do that? (code, error messages) Have you verified that the const and mutable indirect_iterators interoperate the way you'd like?
and a number of more complicated combinations of the 3. No matter which I try I get errors about the const_reverse_iterator not playing nicely with the reverse_iterator. I think I've read everything on the list archives about indirect_iterator, but perhaps I missed something. I'm going to try my code on g++ (currently using VC 7.1) and then work on a complete example, but I thought I'd throw this out and see if someone can quickly answer it.
No obvious ideas, sorry. -- Dave Abrahams Boost Consulting www.boost-consulting.com

On Tue, 01 Mar 2005 12:55:21 -0500, David Abrahams <dave@boost-consulting.com> wrote:
Thomas Matelich <matelich@gmail.com> writes:
I'm a little behind the times and am trying to port my old iterator_adapters code to use the new library (1.32). We have a class which is little more than a wrapper around a vector<shared_ptr<T> >, and I am having a heck of a time with setting its typedef for reverse_iterator and const_reverse_iterator. I just can't get const_reverse_iterator to do assignment and comparison with reverse_iterator.
I've tried to make indirect_iterators out of the native reverse iterators,
That almost certainly won't work, because the native reverse_iterator usually won't play nicely with the native const_reverse_iterator.
using boost::reverse_iterators of indirect_iterators
What happens when you do that? (code, error messages) Have you verified that the const and mutable indirect_iterators interoperate the way you'd like?
So, of course, my sample application (attached) compiles just fine. I went through and made sure I'm using the same compile options in my sample project and real project (MSVC 7.1). In my failing version assigning a rev_iterator to a const_rev_iterator fails with the following error: smartlisttest.cpp(352) : error C2440: 'initializing' : cannot convert from 'ZUtil::SmartList<T>::rev_iterator' to 'boost::reverse_iterator<Iterator>' with [ T=TestItem ] and [ Iterator=ZUtil::SmartList<TestItem>::const_iterator ] No constructor could take the source type, or constructor overload resolution was ambiguous Does that error ring a bell? I'm about ready to drop the new iterators or rewrite this class, neither of which I really want to do at this point. Thanks, Tom

Thomas Matelich <matelich@gmail.com> writes:
On Tue, 01 Mar 2005 12:55:21 -0500, David Abrahams <dave@boost-consulting.com> wrote:
Thomas Matelich <matelich@gmail.com> writes:
I'm a little behind the times and am trying to port my old iterator_adapters code to use the new library (1.32). We have a class which is little more than a wrapper around a vector<shared_ptr<T> >, and I am having a heck of a time with setting its typedef for reverse_iterator and const_reverse_iterator. I just can't get const_reverse_iterator to do assignment and comparison with reverse_iterator.
I've tried to make indirect_iterators out of the native reverse iterators,
That almost certainly won't work, because the native reverse_iterator usually won't play nicely with the native const_reverse_iterator.
using boost::reverse_iterators of indirect_iterators
What happens when you do that? (code, error messages) Have you verified that the const and mutable indirect_iterators interoperate the way you'd like?
So, of course, my sample application (attached) compiles just fine.
No it doesn't: vc-C++ c:\build\bin\tmp\foo.test\vc7.1\debug-python\threading-multi\foo.obj foo.cpp foo.cpp(255) : error C2662: 'TestItem::setItemKey' : cannot convert 'this' pointer from 'const boost::detail::add_pointer_impl<T>::no_ref_type' to 'TestItem &' with [ T=const boost::detail::iterator_facade_types<boost::mpl::identity<boost::detail::smart_ptr_pointee<boost::detail::indirect_base<ZUtil::SmartList<TestItem>::native_iterator,boost::use_default,boost::use_default,boost::use_default,boost::use_default>::dereferenceable>::type>::type,boost::mpl::identity<boost::random_access_traversal_tag>::type,boost::mpl::identity<boost::detail::smart_ptr_reference<boost::detail::indirect_base<ZUtil::SmartList<TestItem>::native_iterator,boost::use_default,boost::use_default,boost::use_default,boost::use_default>::dereferenceable>::type >::type ,boost::iterator_difference<ZUtil::SmartList<TestItem>::native_iterator>::type>::value_type ] Conversion loses qualifiers But of course, you should have commented out the line that says:
c_r_iter->setItemKey(33,33); //does compile for new
Then it does compile just fine. Clearly you are doing something significantly different in your sample application.
In my failing version assigning a rev_iterator to a const_rev_iterator fails with the following error:
smartlisttest.cpp(352) : error C2440: 'initializing' : cannot convert from 'ZUtil::SmartList<T>::rev_iterator' to 'boost::reverse_iterator<Iterator>' with [ T=TestItem ] and [ Iterator=ZUtil::SmartList<TestItem>::const_iterator ] No constructor could take the source type, or constructor overload resolution was ambiguous
Well, it seems as though ZUtil::SmartList<TestItem>::rev_iterator and boost::reverse_iterator<ZUtil::SmartList<TestItem>::const_iterator> must not be the same type in your failing version. If the problem isn't immediately obvious, I suggest you run your code through the VC8 public beta. Jason Shirk, at my urging, implemented a fix to the error reporting that will unwind the typedefs in the error message so you can see what types are actually involved. -- Dave Abrahams Boost Consulting www.boost-consulting.com

Thanks for the tips on tracking it down. For the time being, I'm just changing implicit conversions of rev_iterator to const_rev_iterator. It's not that important a feature for the amount of time I've been spending on it. On Mon, 07 Mar 2005 21:05:52 -0500, David Abrahams <dave@boost-consulting.com> wrote:
Thomas Matelich <matelich@gmail.com> writes:
On Tue, 01 Mar 2005 12:55:21 -0500, David Abrahams <dave@boost-consulting.com> wrote:
Thomas Matelich <matelich@gmail.com> writes:
I'm a little behind the times and am trying to port my old iterator_adapters code to use the new library (1.32). We have a class which is little more than a wrapper around a vector<shared_ptr<T> >, and I am having a heck of a time with setting its typedef for reverse_iterator and const_reverse_iterator. I just can't get const_reverse_iterator to do assignment and comparison with reverse_iterator.
I've tried to make indirect_iterators out of the native reverse iterators,
That almost certainly won't work, because the native reverse_iterator usually won't play nicely with the native const_reverse_iterator.
using boost::reverse_iterators of indirect_iterators
What happens when you do that? (code, error messages) Have you verified that the const and mutable indirect_iterators interoperate the way you'd like?
So, of course, my sample application (attached) compiles just fine.
No it doesn't:
vc-C++ c:\build\bin\tmp\foo.test\vc7.1\debug-python\threading-multi\foo.obj foo.cpp foo.cpp(255) : error C2662: 'TestItem::setItemKey' : cannot convert 'this' pointer from 'const boost::detail::add_pointer_impl<T>::no_ref_type' to 'TestItem &' with [ T=const boost::detail::iterator_facade_types<boost::mpl::identity<boost::detail::smart_ptr_pointee<boost::detail::indirect_base<ZUtil::SmartList<TestItem>::native_iterator,boost::use_default,boost::use_default,boost::use_default,boost::use_default>::dereferenceable>::type>::type,boost::mpl::identity<boost::random_access_traversal_tag>::type,boost::mpl::identity<boost::detail::smart_ptr_reference<boost::detail::indirect_base<ZUtil::SmartList<TestItem>::native_iterator,boost::use_default,boost::use_default,boost::use_default,boost::use_default>::dereferenceable>::type >::type ,boost::iterator_difference<ZUtil::SmartList<TestItem>::native_iterator>::type>::value_type ] Conversion loses qualifiers
But of course, you should have commented out the line that says:
c_r_iter->setItemKey(33,33); //does compile for new
Then it does compile just fine. Clearly you are doing something significantly different in your sample application.
In my failing version assigning a rev_iterator to a const_rev_iterator fails with the following error:
smartlisttest.cpp(352) : error C2440: 'initializing' : cannot convert from 'ZUtil::SmartList<T>::rev_iterator' to 'boost::reverse_iterator<Iterator>' with [ T=TestItem ] and [ Iterator=ZUtil::SmartList<TestItem>::const_iterator ] No constructor could take the source type, or constructor overload resolution was ambiguous
Well, it seems as though
ZUtil::SmartList<TestItem>::rev_iterator
and
boost::reverse_iterator<ZUtil::SmartList<TestItem>::const_iterator>
must not be the same type in your failing version. If the problem isn't immediately obvious, I suggest you run your code through the VC8 public beta. Jason Shirk, at my urging, implemented a fix to the error reporting that will unwind the typedefs in the error message so you can see what types are actually involved.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Mon, 07 Mar 2005 21:05:52 -0500, David Abrahams <dave@boost-consulting.com> wrote:
Thomas Matelich <matelich@gmail.com> writes:
On Tue, 01 Mar 2005 12:55:21 -0500, David Abrahams <dave@boost-consulting.com> wrote: So, of course, my sample application (attached) compiles just fine.
No it doesn't:
vc-C++ c:\build\bin\tmp\foo.test\vc7.1\debug-python\threading-multi\foo.obj foo.cpp foo.cpp(255) : error C2662: 'TestItem::setItemKey' : cannot convert 'this' pointer from 'const boost::detail::add_pointer_impl<T>::no_ref_type' to 'TestItem &'
But of course, you should have commented out the line that says:
c_r_iter->setItemKey(33,33); //does compile for new
Then it does compile just fine. Clearly you are doing something significantly different in your sample application.
May I ask what compile options you used to get this to not compile? Also, if you're using the 1.32.0 release or CVS? I just tried to build it again and it only warned about my unused vars. Thanks Tom

Thomas Matelich <matelich@gmail.com> writes:
On Mon, 07 Mar 2005 21:05:52 -0500, David Abrahams <dave@boost-consulting.com> wrote:
Thomas Matelich <matelich@gmail.com> writes:
On Tue, 01 Mar 2005 12:55:21 -0500, David Abrahams <dave@boost-consulting.com> wrote: So, of course, my sample application (attached) compiles just fine.
No it doesn't:
vc-C++ c:\build\bin\tmp\foo.test\vc7.1\debug-python\threading-multi\foo.obj foo.cpp foo.cpp(255) : error C2662: 'TestItem::setItemKey' : cannot convert 'this' pointer from 'const boost::detail::add_pointer_impl<T>::no_ref_type' to 'TestItem &'
But of course, you should have commented out the line that says:
c_r_iter->setItemKey(33,33); //does compile for new
Then it does compile just fine. Clearly you are doing something significantly different in your sample application.
May I ask what compile options you used to get this to not compile?
Standard bjam: /Zm800 -nologo /EHsc -c /Z7 /Od /Ob0 /EHsc /GR /MDd /Op /Zc:wchar_t,forScope -I"c:\boost"
Also, if you're using the 1.32.0 release or CVS?
CVS. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Thomas Matelich