Topic: Inconsistence of list::resize in CD2


Author: James Kuyper <kuyper@wizard.net>
Date: 1998/12/12
Raw View
AllanW@my-dejanews.com wrote:
>
> In article <366edb6b.0@monster.ssau.ru>,
>   "Vlad Harchev" <vladhar@imimail.ssau.ru> wrote:
> >  Hey!
> Hey!
>
> > I think that everybody understands that list<T>::iterator doesn't have
> > operator+ - so this seems a bug in the standard (or in CD2 at least). Any
> > opinions?
>
> This isn't a bug. It was done on purpose, because in a list you can't
> jump to an arbitrary element in constant time. Look up list::advance()
> for an alternative way to do what you seem to want.

Vlad should have included more context. Given that he didn't, you should
have checked the references. He's not suggesting that list<>::iterator
should have an operator+.  He was responding to a message that pointed
out an 'effects' clause in the standard that implies that begin()+sz is
a meaningful expression for a list<>.


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: AllanW@my-dejanews.com
Date: 1998/12/10
Raw View
In article <366edb6b.0@monster.ssau.ru>,
  "Vlad Harchev" <vladhar@imimail.ssau.ru> wrote:
>  Hey!
Hey!

> I think that everybody understands that list<T>::iterator doesn't have
> operator+ - so this seems a bug in the standard (or in CD2 at least). Any
> opinions?

This isn't a bug. It was done on purpose, because in a list you can't
jump to an arbitrary element in constant time. Look up list::advance()
for an alternative way to do what you seem to want.

--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1998/12/09
Raw View
In article <366edb6b.0@monster.ssau.ru>, Vlad Harchev
<vladhar@imimail.ssau.ru> writes
> Hey! I think that everybody understands that list<T>::iterator doesn't have
>operator+ - so this seems a bug in the standard (or in CD2 at least). Any
>opinions?

Explain why you think it should have.  Better, go and read 'Generic
Programming with the STL' by Matt Austern and then raise the issue again
if you think you should.


Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 1998/12/10
Raw View
Francis Glassborow wrote:
>
> In article <366edb6b.0@monster.ssau.ru>, Vlad Harchev
> <vladhar@imimail.ssau.ru> writes
> > Hey! I think that everybody understands that list<T>::iterator doesn't have
> >operator+ - so this seems a bug in the standard (or in CD2 at least). Any
> >opinions?
>
> Explain why you think it should have.  Better, go and read 'Generic
> Programming with the STL' by Matt Austern and then raise the issue again
> if you think you should.

He's not suggesting that list<>::iterator should have an operator+; he's
complaining that the Standard contains an 'effects' clause (23.2.2.2)
which is described in terms of that non-existence operator. It should
say advance(begin(), sz), not begin()+sz.


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/12/10
Raw View
James Kuyper wrote:
>
> Francis Glassborow wrote:
> >
> > In article <366edb6b.0@monster.ssau.ru>, Vlad Harchev
> > <vladhar@imimail.ssau.ru> writes
> > > Hey! I think that everybody understands that list<T>::iterator doesn't have
> > >operator+ - so this seems a bug in the standard (or in CD2 at least). Any
> > >opinions?

> he's
> complaining that the Standard contains an 'effects' clause (23.2.2.2)
> which is described in terms of that non-existence operator. It should
> say advance(begin(), sz), not begin()+sz.

It's generally understoud that the description of a function
doesn't need to be runable code and may contain non existent,
but meaningful, operators.

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1998/12/10
Raw View
In article <366F1B8D.85924371@wizard.net>, James Kuyper
<kuyper@wizard.net> writes
>> Explain why you think it should have.  Better, go and read 'Generic
>> Programming with the STL' by Matt Austern and then raise the issue again
>> if you think you should.
>
>He's not suggesting that list<>::iterator should have an operator+; he's
>complaining that the Standard contains an 'effects' clause (23.2.2.2)
>which is described in terms of that non-existence operator. It should
>say advance(begin(), sz), not begin()+sz.

Sorry, I misunderstood, but in doing so gave the lie to his premise:).



Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/12/09
Raw View

 Hey! I think that everybody understands that list<T>::iterator doesn't have
operator+ - so this seems a bug in the standard (or in CD2 at least). Any
opinions?

-Vlad



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/12/04
Raw View
  In CD2, in [lib.list.capacity], the following is stated:
quote begin:
  void resize(size_type sz, T c = T());
  Effects:
        if (sz > size())
          insert(end(), sz-size(), c);
        else if (sz < size())
          erase(begin()+sz, end());
        else
          ; // do nothing
quote end
 Note in the 3rd line from the tail of this:
          erase(begin()+sz, end());
 But list::iterator is not random access iterator, so 'begin()+sz' can
confuse the reader.
 - Vlad




[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]