From 165670474883063091
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,31085442cf446f1e,start
X-Google-Attributes: gidf78e5,public
From: bparker@gil.com.au (Brian Parker)
Subject: Re: "Modifying algorithms" aren't??
Date: 1997/05/28
Message-ID: <338cfe55.15140972@news.ipswich.gil.com.au>#1/1
X-Deja-AN: 244651000
References: <5mfoo2$vj8$1@alpha.wright.edu>
X-Original-Date: Thu, 29 May 1997 04:06:48 GMT
Organization: Global Info-Links News Server
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBM40TDUy4NqrwXLNJAQFn2wH/dQNOQ8+Y1B+9J4E6OD9nr7SclDehV+t6 WJM4Wo6r6yVfBLKMlQ6dgfKo7B9U/1/QfNJCRevOZDJzXe5zdeoV/g== =cT2G
Newsgroups: comp.std.c++
Originator: austern@isolde.mti.sgi.com


On 28 May 97 09:12:37 GMT, pedwards@cs.wright.edu (Phil Edwards)
wrote:

>CD2 doesn't specify one way or the other that I can find, but it seems
>that the HP-as-modified-for-DEC implementation of the algorithms in
>25.2, [lib.alg.modifying.operations], are behaving very non-intuitively.
>
>Specifically, "deleting" members of a container, by whatever method, only
>copies the remaining elements "up" a place in the container, leaving
>copies of the last element in the container.  It seems that this would be
>fine (lazy deallocation), BUT the extraneous copy at the end is still
>being included in the container's membership.
>
>As example, this:
>
>	deque<int>    foo;
>	for (int i=0; i<20; i++)  foo.push_back(i);
>
>	cerr << "Original foo:\n";
>	copy (foo.begin(), foo.end(), ostream_iterator<int>(cerr, " "));
>
>	remove (foo.begin(), foo.end(), 14);
>
>	cerr << "\n\nNew foo:\n";
>	copy (foo.begin(), foo.end(), ostream_iterator<int>(cerr, " "));
>	cerr << endl;
>
>results in:
>
>	Original foo:
>	0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
>
>	New foo:
>	0 1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 19 
>                                                       ^^-- ugh
>
>I realize that remove() and similar algorithms return "the end of the
>resulting range".
>...

With the iterator returned from remove( ), you can call erase( ) on
the deque itself to actually delete the elements.

(The generic algorithms, acting through iterators, don't have access
to the original container and so can't remove the elements from the
container)

,Brian Parker (bparker@gil.com.au)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



