Hi, regarding iterator_adaptor<>, I've created a custom iterator over a map as below. Basically, it allows to iterate over map values without being worried with key values. Anyway, if I would want to do something like this: typedef map<int,int> map_type; typedef map_data_iterator<map_type::iterator> map_iterator; map_type map; map_iterator it = map_data_iterator(map.begin()); for (; it != map.end(); ++map) ... I'd have to add an equal method to the map_data_iterator class that takes the base type iterator, right? I tried to do so below, but it still complains about not being able to convert: binary '!=' : no operator found which takes a left-hand operand of type 'OpenTissue::DepthFirstTesselator<Types>::prism_iterator' (or there is no acceptable conversion) I know this is probably not the right thing(tm) to do , but I basically need to be able to do this comparison for backward compatibility with deprecated code. Thanks, --nico template <class Iterator> class map_data_iterator : public iterator_adaptor< map_data_iterator<Iterator>, Iterator, typename Iterator::value_type::second_type > { typedef typename map_data_iterator::iterator_adaptor_ super_t; typedef typename Iterator::value_type pair_type; typedef typename pair_type::second_type second_type; friend class iterator_core_access; public: map_data_iterator() {} // should be explicit, but removed to give OpenTissue backwards compatibility map_data_iterator(Iterator x) : super_t(x) {} template<class OtherIterator> map_data_iterator( map_data_iterator<OtherIterator> const& r , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 ) : super_t(r.base()) {} private: second_type & dereference() const { return this->base()->second; } // added to give support for comparison with base type iterators //bool equal(Iterator const& other) const //{ // return (this->base() == other); //} //bool equal(super_t const& other) const //{ // return (*this == other); //} }; -- nico galoppo von borries @ address: 105 creel st., chapel hill comp. graphics phd. student @ north carolina, 27516 USA UNC, chapel hill @ phone: +1 (919) 962-1898 (office) @ +1 (919) 942-7609 (home) @ email: nico at cs dot unc dot edu @ homepage: http://www.cs.unc.edu/~nico --- debian linux :: vim powered
Nico Galoppo <nico@crossbar.net> writes:
Hi,
regarding iterator_adaptor<>, I've created a custom iterator over a map as below. Basically, it allows to iterate over map values without being worried with key values.
For that I would use transform_iterator with an appropriate select_2nd function object.
Anyway, if I would want to do something like this:
typedef map<int,int> map_type; typedef map_data_iterator<map_type::iterator> map_iterator; map_type map;
map_iterator it = map_data_iterator(map.begin()); for (; it != map.end(); ++map) ...
I'd have to add an equal method to the map_data_iterator class that takes the base type iterator, right?
Something like that. Of course you need != as well (that doesn't come along for free). A family of free friend functions would be better, since in the usage above, it would have to be a member of map_iterator, which you don't control.
I tried to do so below, but it still complains about not being able to convert:
binary '!=' : no operator found which takes a left-hand operand of type 'OpenTissue::DepthFirstTesselator<Types>::prism_iterator' (or there is no acceptable conversion)
I know this is probably not the right thing(tm) to do , but I basically need to be able to do this comparison for backward compatibility with deprecated code.
You shouldn't need the != and == overloads at all since you have an implicit converting constructor. So I think there's something wrong with your compiler or there's some deeper subtlety here. Is map.end() returning the map's const_iterator? You don't have a conversion for that one. -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
You shouldn't need the != and == overloads at all since you have an implicit converting constructor. So I think there's something wrong with your compiler or there's some deeper subtlety here. Is map.end() returning the map's const_iterator? You don't have a conversion for that one.
It's bizarre: typedef Prism prism_type; typedef typename std::map<face_type const*, prism_type> prism_map; typedef typename prism_map::iterator base_prism_iterator; typedef map_data_iterator<base_prism_iterator> prism_iterator; bool debug_verify( prism_map & prisms ) { for ( prism_iterator prism = prisms.begin(); prism!=prisms.end(); ++prism) } Once again, thanks alot, --nico d:\dev\OpenTissue\OpenTissue\t4mesh\util\thin_shell\policies\depth_first_tesselator.h(316) : error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'OpenTissue::DepthFirstTesselator<Types>::prism_iterator' (or there is no acceptable conversion) with [ Types=OpenTissue::ThinShellTypeBinder<vector3_type,core_mesh_type,surface_mesh_type,OpenTissue::AngleWeightedNormals,OpenTissue::MaximumGlobalExtrusion,OpenTissue::DepthFirstTesselator>::Types ] d:\dev\OpenTissue\OpenTissue\t4mesh\util\thin_shell\policies\depth_first_tesselator.h(315) : while compiling class-template member function 'bool OpenTissue::DepthFirstTesselator<Types>::debug_verify(OpenTissue::DepthFirstTesselator<Types>::prism_map &)' with [ Types=OpenTissue::ThinShellTypeBinder<vector3_type,core_mesh_type,surface_mesh_type,OpenTissue::AngleWeightedNormals,OpenTissue::MaximumGlobalExtrusion,OpenTissue::DepthFirstTesselator>::Types ] d:\dev\OpenTissue\OpenTissue\t4mesh\util\thin_shell\thin_shell.h(53) : see reference to class template instantiation 'OpenTissue::DepthFirstTesselator<Types>' being compiled with [ Types=OpenTissue::ThinShellTypeBinder<vector3_type,core_mesh_type,surface_mesh_type,OpenTissue::AngleWeightedNormals,OpenTissue::MaximumGlobalExtrusion,OpenTissue::DepthFirstTesselator>::Types ] D:\dev\Hybrid\Hybrid\utility\model_make_thinshell.h(43) : see reference to class template instantiation 'OpenTissue::ThinShell<Types>' being compiled with [ Types=thin_shell_types ] src\application.cpp(314) : see reference to function template instantiation 'void Hybrid::model_make_thinshell<T,Application::model_type>(mesh_type &,model_type &)' being compiled -- nico galoppo von borries @ address: 105 creel st., chapel hill comp. graphics phd. student @ north carolina, 27516 USA UNC, chapel hill @ phone: +1 (919) 962-1898 (office) @ +1 (919) 942-7609 (home) @ email: nico at cs dot unc dot edu @ homepage: http://www.cs.unc.edu/~nico --- debian linux :: vim powered
Nico Galoppo <nico@crossbar.net> writes:
David Abrahams wrote:
You shouldn't need the != and == overloads at all since you have an implicit converting constructor.
That was wrong; I forgot that the operators== and != for iterator_facade are templated, so no user-defined conversions will be considered. You need to implement your own overloads, preferably as free functions. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Nico Galoppo