[geos-devel] Iterator adapter - question

strk at refractions.net strk at refractions.net
Fri May 26 05:16:47 EDT 2006


Mateus, the whole issue is related to make a std::map iterator
return values rather then pair(key,value) so we can't consider
them "exception" but rather the main focus.

Probably a MapValueIterator would do as we wouldn't need an
adapter for the other containers. I already suggested a simpler
interface: only use for the iterator would be:

	comparison ( current != end ) // map_iter == other.map_iter
	dereference ( *current ) // return map_iter->second
	advance ( ++current; current++; ) // ++map_iter; map_iter++


I don't know if making this a STL-compatible iterator would do.
For example, would standard algorithms rely on the *dereference
operator ? Note that we wouldn't need most operations defined
for standard iterators.

--strk;


On Fri, May 26, 2006 at 10:22:03AM +0200, Mateusz Loskot wrote:
> Hi Sandro,
> 
> I have 2-3 concepts about the generic iterator adapter
> but I'd need some details how would you like to use it.
> If you could provide me with some pseudo-code
> or some assumptions that would be helpful.
> I know the idea but I'd need to know what kind of information
> do you want to provide to the adapter and what information
> you want to be deduced automatically.
> 
> There are a few possibilities, the idea is to have adapter unifying
> iterators from STL containers, so you will be able to apply
> the same algorithm on different collections.
> This is quite simple idea and the only exceptions are trees:
> map and multimap containers.
> 
> Simples possibility is to specialize the adapter with container:
> 
> adapter<std::vector<T> > ( v.begin() );
> adapter<std::list<T> > ( v.begin() );
> 
>  where T is a type of objects stored in container
> 
> adapter<std::map<K,V> > ( m.begin() );
> 
>  where K is a key type and V is a mapped value type
> 
> Another option is to specialize only with base iterator:
> adapter<std::list<T>::iterator> ( v.begin() );
> adapter<std::map<K,V>::iterator> ( v.begin() );
> 
> but here the std::map is problematic, because there the adapter is
> specialized for map in more sophisticated way - we need a special
> dereferencing to make adapter returning only value type, not the pair of
> key and value.
> 
> Is this similar to your idea?
> 
> Cheers
> -- 
> Mateusz Łoskot
> http://mateusz.loskot.net
> _______________________________________________
> geos-devel mailing list
> geos-devel at geos.refractions.net
> http://geos.refractions.net/mailman/listinfo/geos-devel

-- 

 /"\    ASCII Ribbon Campaign
 \ /    Respect for low technology.
  X     Keep e-mail messages readable by any computer system.
 / \    Keep it ASCII. 




More information about the geos-devel mailing list