Josuttis comments that to get copy_if functionality, one should use
remove_copy_if. But that removes the copied items from the original container.
Yes, copy_if is trivial to implement, but why did the committee (and/or
Stepanov&Lee) not put it into the STL? 8 8654
On Wed, 22 Oct 2003 04:15:20 GMT, red floyd <no*****@here.dude> wrote: Josuttis comments that to get copy_if functionality, one should use remove_copy_if. But that removes the copied items from the original container.
No it doesn't. It copies items from one range to another, skipping those
that match the condition. The source range is not modified.
*None* of the STL algorithms remove elements from containers. Since they work
on arrays, and it is impossible to change the length of an array in C++.
Yes, copy_if is trivial to implement, but why did the committee (and/or Stepanov&Lee) not put it into the STL?
It was an oversight, for which Stroustrup apologises in "The C++ Programming
Language".
But remove_copy_if works just fine, you just have to negate the test.
--
Sam Holden
> Yes, copy_if is trivial to implement, but why did the committee (and/or Stepanov&Lee) not put it into the STL?
A mistake. It will be in the next version.
Stephen Howe
In article <sv*****************@newssvr29.news.prodigy.com> , no*****@here.dude says... Josuttis comments that to get copy_if functionality, one should use remove_copy_if. But that removes the copied items from the original container.
No, it does not. It simply skips copying any item that meets the
specified criteria. IOW, copy_if would be basically identical to
remove_copy_if, except that the predicate is logically negated.
--
Later,
Jerry.
The universe is a figment of its own imagination.
Jerry Coffin wrote: In article <sv*****************@newssvr29.news.prodigy.com> , no*****@here.dude says...
Josuttis comments that to get copy_if functionality, one should use remove_copy_if. But that removes the copied items from the original container.
No, it does not. It simply skips copying any item that meets the specified criteria. IOW, copy_if would be basically identical to remove_copy_if, except that the predicate is logically negated.
I was looking at Josuttis, page 380:
"remove_copy_if() is a combination of copy() and remove_if(). It *removes each element in the source range*
[beg,end) for which the unary predicate op(elem) yields true while the elements are copied into the destination range
starting with destBeg". (emphasis mine)
The wording was such that I thought they were removed from the source container. However, looking at the sample
program and its output, I see that I was mistaken.
Thanks
In article <mB*********************@newssvr21.news.prodigy.co m>, no*****@here.dude says...
[ ... ] I was looking at Josuttis, page 380:
Yup -- a poor explanation. One of the few flaws in an excellent book.
--
Later,
Jerry.
The universe is a figment of its own imagination.
"Jerry Coffin" <jc*****@taeus.com> wrote in message
news:MP************************@news.clspco.adelph ia.net... In article <mB*********************@newssvr21.news.prodigy.co m>, no*****@here.dude says...
[ ... ]
I was looking at Josuttis, page 380:
Yup -- a poor explanation. One of the few flaws in an excellent book.
From http://www.josuttis.com/libbook/errata1_5.html :
================================================== ===================
Page 380, Section 9.7.1
The descriptions of remove_copy() and remove_copy_if() are misleading.
Replace the second sentence of the first item by:
It copies each element in the source range [beg,end) that is not equal to
value into the destination range starting with destBeg.
Replace the second sentence of the second item by:
It copies each element in the source range [beg,end) for which the unary
predicate op(elem) yields false into the destination range starting with
destBeg.
================================================== ===================
-Mike
Mike Wahler wrote: "Jerry Coffin" <jc*****@taeus.com> wrote in message news:MP************************@news.clspco.adelph ia.net...
In article <mB*********************@newssvr21.news.prodigy.co m>, no*****@here.dude says...
[ ... ]
I was looking at Josuttis, page 380:
Yup -- a poor explanation. One of the few flaws in an excellent book.
From http://www.josuttis.com/libbook/errata1_5.html :
================================================== =================== Page 380, Section 9.7.1
The descriptions of remove_copy() and remove_copy_if() are misleading. Replace the second sentence of the first item by:
It copies each element in the source range [beg,end) that is not equal to value into the destination range starting with destBeg.
Replace the second sentence of the second item by:
It copies each element in the source range [beg,end) for which the unary predicate op(elem) yields false into the destination range starting with destBeg. ================================================== ===================
Thanks! I needed that!
"red floyd" <no*****@here.dude> wrote in message
news:iY****************@newssvr14.news.prodigy.com ... Mike Wahler wrote: From http://www.josuttis.com/libbook/errata1_5.html :
================================================== =================== Page 380, Section 9.7.1
Thanks! I needed that!
I found this by following a link provided in,
you guessed it, the book itself. :-)
-Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sks_cpp |
last post by:
I am somewhat new to STL and the plethora of library functions they have. I
looked at sgi's stl info. and I was overwhelmed so I thought I would present
my question here.
I have
std::map<WWN*,...
|
by: mead |
last post by:
The code is from a Meyers' book...
class BankAccount { ... }; // as above
// new class representing accounts that bear interest
class InterestBearingAccount: public BankAccount {
public:...
|
by: jota |
last post by:
Is there any more hands on way to make a copy of a vector where pred is
TRUE.(in the code snip)
And I need a copy becourse OnFX might or might not alter List.
typedef std::vector<CS *> LIST;...
|
by: john.burton |
last post by:
I used to use c++ a lot but recently I've been using java and pythons
and I'm finding it a lot harder to think of the best way to do
something in C++
Imagine I want a function that returns a...
|
by: silverburgh.meryl |
last post by:
In STL, there is no copy_if algorithm. But how can I emulate that?
I am thinking about using find_if and then a copy.
But how can I pass the InputIterator (begin and end) to copy so that it
knows...
| |
by: Minkoo Seo |
last post by:
Hi list.
I'm trying to implment copy_if using boost::lambda:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
|
by: kaferro |
last post by:
What is the typical way to loop through a vector while deleting
certain elements during the loop process? The code below works, but I
am wondering if there is a better solution.
...
|
by: arnuld |
last post by:
It works fine. any advice on making it better or if I can
improve my C++ coding skills:
/* C++ Primer - 4/e
*
* Chapter 9 - Sequential Containers
* exercise 9.18 - STATEMENT
* ...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |