Valhalla Legends Forums Archive | C/C++ Programming | Legal C++ or not?

AuthorMessageTime
Skywing
[code]
#include <list>

int main(int ac, char **av)
{
std::list<int> l;

for(std::list<int>::const_reverse_iterator i = l.rbegin(); i != l.rend(); ++i) ;

return 0;
}
[/code]

I'm currrently pending a response from Bjarne Stroustrup on this.

It doesn't compile with VC < VC8 beta 1 (e.g. with the Dinkumware STL), Comeau C++ (with the SGI STL), or GCC (with it's default STL).

What do you think?
November 7, 2004, 4:03 PM
Mephisto
[quote author=Skywing link=topic=9456.msg87772#msg87772 date=1099843395]
[code]
#include <list>

int main(int ac, char **av)
{
std::list<int> l;

for(std::list<int>::const_reverse_iterator i = l.rbegin(); i != l.rend(); ++i) ;

return 0;
}
[/code]

I'm currrently pending a response from Bjarne Stroustrup on this.

It doesn't compile with VC < VC8 beta 1 (e.g. with the Dinkumware STL), Comeau C++ (with the SGI STL), or GCC (with it's default STL).

What do you think?
[/quote]

The compiler seems to complain about i != l.rend() in terms of not supplying valid operator operands.
November 7, 2004, 6:51 PM
Skywing
[quote author=Mephisto link=topic=9456.msg87792#msg87792 date=1099853503]
[quote author=Skywing link=topic=9456.msg87772#msg87772 date=1099843395]
[code]
#include <list>

int main(int ac, char **av)
{
std::list<int> l;

for(std::list<int>::const_reverse_iterator i = l.rbegin(); i != l.rend(); ++i) ;

return 0;
}
[/code]

I'm currrently pending a response from Bjarne Stroustrup on this.

It doesn't compile with VC < VC8 beta 1 (e.g. with the Dinkumware STL), Comeau C++ (with the SGI STL), or GCC (with it's default STL).

What do you think?
[/quote]

The compiler seems to complain about i != l.rend() in terms of not supplying valid operator operands.
[/quote]
I know what the compiler says.  I'm asking if this is legal with a perfectly conforming C++ compiler and a perfectly conforming C++ STL.
November 7, 2004, 7:43 PM
Mephisto
It appears to be completely fine/legal.  If you don't use a reverse iterator it compiles (providing you use begin and end not rbegin and rend).  Interesting.
November 7, 2004, 7:49 PM
kamakazie
Why not?

[code]
#include <list>

int main(int ac, char **av)
{
std::list<int> l;

for(std::list<int>::reverse_iterator i = l.rbegin(); i != l.rend(); ++i) ;

return 0;
}
[/code]

Why must i be const_reverse_iterator?
November 7, 2004, 7:54 PM
Skywing
[quote author=dxoigmn link=topic=9456.msg87809#msg87809 date=1099857272]
Why not?

[code]
#include <list>

int main(int ac, char **av)
{
std::list<int> l;

for(std::list<int>::reverse_iterator i = l.rbegin(); i != l.rend(); ++i) ;

return 0;
}
[/code]

Why must i be const_reverse_iterator?
[/quote]

The problem is exhibited with const_reverse_iterator.  This is a simple test case to show that.
November 7, 2004, 9:26 PM
Eibro
Have you tried with STLport?
November 7, 2004, 10:04 PM
Skywing
[quote author=Eibro[yL] link=topic=9456.msg87827#msg87827 date=1099865048]
Have you tried with STLport?
[/quote]
No; I don't have it installed.  BTW, isn't that related to the SGI STL, though (which failed)?
November 8, 2004, 1:22 AM
Skywing
Bjarne answers the question:

[quote]The program is *not* legal. You can convert an iterator to a
const_iterator, but it is not guaranteed that you can convert a
reverse_iterator to a const_reverse_iterator. This is a known problem
that is likely to be corrected in the next revision of the standard. In
the meantime, the implementors are reluctant to provide that conversion
because that would lead to non-protable user code. I don't know of any
good reason why it is not allowed.[/quote]
November 10, 2004, 4:11 PM
warz
I've met Bjarne before when I visited college station. I believe torque has him for computer science.
November 11, 2004, 4:22 AM

Search