• Welcome to Valhalla Legends Archive.
 

Legal C++ or not?

Started by Skywing, November 07, 2004, 10:03 AM

Previous topic - Next topic

Skywing


#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;
}


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?

Mephisto

#1
Quote from: Skywing on November 07, 2004, 10:03 AM

#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;
}


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?

The compiler seems to complain about i != l.rend() in terms of not supplying valid operator operands.

Skywing

Quote from: Mephisto on November 07, 2004, 12:51 PM
Quote from: Skywing on November 07, 2004, 10:03 AM

#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;
}


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?

The compiler seems to complain about i != l.rend() in terms of not supplying valid operator operands.
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.

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.

dxoigmn

Why not?


#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;
}


Why must i be const_reverse_iterator?

Skywing

Quote from: dxoigmn on November 07, 2004, 01:54 PM
Why not?


#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;
}


Why must i be const_reverse_iterator?

The problem is exhibited with const_reverse_iterator.  This is a simple test case to show that.

Eibro

Have you tried with STLport?
Eibro of Yeti Lovers.

Skywing

Quote from: Eibro[yL] on November 07, 2004, 04:04 PM
Have you tried with STLport?
No; I don't have it installed.  BTW, isn't that related to the SGI STL, though (which failed)?

Skywing

Bjarne answers the question:

QuoteThe 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.

warz

#9
I've met Bjarne before when I visited college station. I believe torque has him for computer science.