Chris Larrieu wrote:
>
> The comparison between an iterator and a const_iterator is not
> defined by the standard. The only portable solution is to
> cast my_list.end() to a const iterator:
>
> if (it != (list<t>::const_iterator)my_list.end())
> cout << "groovy" << endl;
The following should be portable:
if (my_list.end() != it)
I suspect the Standard requires that a const_iterator can be implicitly
created from an iterator, although I don't know for sure (I can't find
very much about const_iterator in it, but I may be looking in the wrong
places). In the above case, if no suitable comparison operator (cit !=
it) exists then the compiler will automatically convert the RHS to cit and
use (cit != cit).
> But, both g++ and MS VC++ quietly permit the first comparison,
> while the HP aCC compiler specifically disallows it, specifically
> because it's undefined. You might take this in one of two ways:
> either as evidence that HP is behind the times, or that HP avoids
> supporting de facto standards.
My current list implementation allows either order in comparisons, but I
could take out the (it == cit) operations if you really think this is
necessary. I'm not sure that we'll be switching over to vendor's list
classes for quite a long time though - Tornado 2 is the worst performer,
and I can't see that being updated anytime soon.
- Andrew
--
Every great idea appears crazy to start with.
- Replies:
- Re: C++ API backwards compatibility Chris Larrieu
- References:
- C++ API backwards compatibility Jeff Hill
- Re: C++ API backwards compatibility Andrew Johnson
- Re: C++ API backwards compatibility Chris Larrieu
- Re: C++ API backwards compatibility Andrew Johnson
- Re: C++ API backwards compatibility Chris Larrieu
- Navigate by Date:
- Prev:
Re: C++ API backwards compatibility Chris Larrieu
- Next:
Re: C++ API backwards compatibility Chris Larrieu
- Index:
1994
1995
1996
1997
1998
1999
<2000>
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: C++ API backwards compatibility Chris Larrieu
- Next:
Re: C++ API backwards compatibility Chris Larrieu
- Index:
1994
1995
1996
1997
1998
1999
<2000>
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|