Topic: std::set::iterator revisited


Author: kjawolf@yahoo.com (Ken Aarts)
Date: Thu, 22 Aug 2002 19:01:46 GMT
Raw View
rmaddox@isicns.com (Randy Maddox) wrote in message news:<8c8b368d.0208200933.69dad65e@posting.google.com>...
> kjawolf@yahoo.com (Ken Aarts) wrote in message news:<e8adcdc7.0208160619.76023460@posting.google.com>...
> > I have a function that takes two pointers to set::iterators,
> > delimiting a range.  I first decided to overload this function for
> > pointers to const_iterators thinking to ensure that incrementing the
> > pointer would always increment by the correct size.  However, when a
> > colleage on a different platform attempted to compile this, he got a
> > function redefinition error.  On his platform, set::iterator and
> > set::const_iterator were both typedef'ed to the underlying
> > tree::const_iterator.
> >
>
> Why does your function take a pointer to an iterator anyway?  You do
> understand that incrementing such a pointer is NOT anything like
> incrementing the iterator itself, and will almost certainly result in
> pointing to garbage?  You are most likely better off just passing the
> iterator by value, but if you do want to access the caller's iterator,
> then pass the iterators by reference.
>
> Randy.
>

My function takes a pointer to an iterator because it is looking at an
array of iterators.

The point of my post is seeing if there is a Standard problem, since
on one implementation, the overloaded function may be necessary, while
on another it is forbidden.

Ke

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rmaddox@isicns.com (Randy Maddox)
Date: 23 Aug 2002 16:15:12 GMT
Raw View
kjawolf@yahoo.com (Ken Aarts) wrote in message news:<e8adcdc7.0208220942.684d89a6@posting.google.com>...
> rmaddox@isicns.com (Randy Maddox) wrote in message news:<8c8b368d.0208200933.69dad65e@posting.google.com>...
> > kjawolf@yahoo.com (Ken Aarts) wrote in message news:<e8adcdc7.0208160619.76023460@posting.google.com>...
> My function takes a pointer to an iterator because it is looking at an
> array of iterators.
>
> The point of my post is seeing if there is a Standard problem, since
> on one implementation, the overloaded function may be necessary, while
> on another it is forbidden.
>
> Ke
>

Well, if you're looking at an array of iterators, what about using a
vector of iterators instead?  Then you could just pass a single
reference to the vector and use begin() and end() to iterate over the
vector of iterators.  Making your function a template on the type of
the vector would generate correct code in each case, and avoid the
whole issue of whether iterator or const_iterator are the same type or
not.

Randy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rmaddox@isicns.com (Randy Maddox)
Date: Tue, 20 Aug 2002 18:50:40 GMT
Raw View
kjawolf@yahoo.com (Ken Aarts) wrote in message news:<e8adcdc7.0208160619.76023460@posting.google.com>...
> I have a function that takes two pointers to set::iterators,
> delimiting a range.  I first decided to overload this function for
> pointers to const_iterators thinking to ensure that incrementing the
> pointer would always increment by the correct size.  However, when a
> colleage on a different platform attempted to compile this, he got a
> function redefinition error.  On his platform, set::iterator and
> set::const_iterator were both typedef'ed to the underlying
> tree::const_iterator.
>

Why does your function take a pointer to an iterator anyway?  You do
understand that incrementing such a pointer is NOT anything like
incrementing the iterator itself, and will almost certainly result in
pointing to garbage?  You are most likely better off just passing the
iterator by value, but if you do want to access the caller's iterator,
then pass the iterators by reference.

Randy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kjawolf@yahoo.com (Ken Aarts)
Date: 16 Aug 2002 15:00:12 GMT
Raw View
I have a function that takes two pointers to set::iterators,
delimiting a range.  I first decided to overload this function for
pointers to const_iterators thinking to ensure that incrementing the
pointer would always increment by the correct size.  However, when a
colleage on a different platform attempted to compile this, he got a
function redefinition error.  On his platform, set::iterator and
set::const_iterator were both typedef'ed to the underlying
tree::const_iterator.

I got around my problem by just rewriting the function as a template
on iterator type, and I realize it could be rewritten not to use
pointers to iterators.  I am left wondering ...

In C++ Standard Library Defect Report List (Revision 22), item 103, it
says that these types may be diffferent, to allow member function
overloading on these types in the future and to rely on automatic
conversion to const_iterator for now.

When they are different types, and may have different sizes, I think I
need both versions of this function.  To have some implementations use
the same type for both types of iterator prevents overloading
functions based on that type.  Is this just a QoI issue, or a defect?

Thanks,
Ken

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]