473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

replace_copy and replace_copy_if

Is the resultant range copied to not necessarily in the order of the
input range? I only have access to the 97 draft standard which doesn't
mention stability. The remove algorithm versions I know are stable but
I'm not sure about the replace algorithm versions.

Fraser.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Sep 30 '06 #1
5 1724
"Fraser Ross" <fraserATmembers.v21.co.ukwrote:
Is the resultant range copied to not necessarily in the order of the
input range? I only have access to the 97 draft standard which doesn't
mention stability. The remove algorithm versions I know are stable but
I'm not sure about the replace algorithm versions.

[25.2.4/3-5]

template<class InputIterator, class OutputIterator, class T>
OutputIterator
replace_copy(InputIterator first, InputIterator last,
OutputIterator result, const T& old_value, const T& new_value);

template<class Iterator, class OutputIterator, class Predicate, class T>
OutputIterator
replace_copy_if(Iterator first, Iterator last,
OutputIterator result, Predicate pred, const T& new_value);

4 Requires: Type T is Assignable (23.1) (and, for replace_copy(),
EqualityComparable (20.1.1). The ranges [first, last) and [result, result +
(last - first)) shall not overlap.

5 Effects: Assigns to every iterator i in the range [result, result +
(last - first)) either new_value or *(first + (i - result)) depending on
whether the following corresponding conditions hold: *(first + (i -
result)) == old_value, pred(*(first + (i - result))) != false.
The way I read this is that the elements are processed in order.
Best

Kai-Uwe Bux
Sep 30 '06 #2
The way I read this is that the elements are processed in order.

The order of invocation and doing a stable copy are not the same thing.
I would expect the intention is to do a stable copy. It should be
stated as it is with the remove algorithms. unique_copy is probably
another that should state a stable copy is done.

Fraser.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Oct 1 '06 #3

Please quote enough material for your post to stand alone. Here is again the
quote from the standard:
[25.2.4/3-5]

template<class InputIterator, class OutputIterator, class T>
OutputIterator
replace_copy(InputIterator first, InputIterator last,
OutputIterator result, const T& old_value, const T& new_value);

template<class Iterator, class OutputIterator, class Predicate, class T>
OutputIterator
replace_copy_if(Iterator first, Iterator last,
OutputIterator result, Predicate pred, const T& new_value);

4 Requires: Type T is Assignable (23.1) (and, for replace_copy(),
EqualityComparable (20.1.1). The ranges [first, last) and [result, result +
(last - first)) shall not overlap.

5 Effects: Assigns to every iterator i in the range [result, result +
(last - first)) either new_value or *(first + (i - result)) depending on
whether the following corresponding conditions hold: *(first + (i -
result)) == old_value, pred(*(first + (i - result))) != false.

"Fraser Ross" <fraserATmembers.v21.co.ukwrote:
>The way I read this is that the elements are processed in order.

The order of invocation and doing a stable copy are not the same thing.
I would expect the intention is to do a stable copy. It should be
stated as it is with the remove algorithms. unique_copy is probably
another that should state a stable copy is done.
The standard does not talk about "order of invocation" at all. It sets which
OutputIterator gets assigned which value: the OutputIterator result+n,
i.e., n slots past result is assigned the value from the InputIterator
from+n or the value new_value depending on the result of the test. This
only specifies the order in which the items will occur in the output
sequence but it does not specify the order in which the necessary
assignments are carried out. In other words, this spells out that the copy
is stable but does not specify the order of any invocations. For example,
if both iterators are bidirectional, the process could go backwards, but
the resulting output sequence is still uniquely determined by the
positional requirements set out in the Effects section.
However, maybe, I misunderstand what you mean.
Best

Kai-Uwe Bux
Oct 1 '06 #4

"Kai-Uwe Bux"
The standard does not talk about "order of invocation" at all.
It does. For for_each there is this:
Effects:
Applies f to the result of dereferencing every iterator in the range
[first, last), starting from first and proceeding to last - 1.
Also it is stated for the <numericsalgorithms and copy/copy_backward.
I see now the copying has to be stable from the description. Most of
what you said I already knew.
Fraser.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Oct 1 '06 #5
"Fraser Ross" <fraserATmembers.v21.co.ukwrote:
>
"Kai-Uwe Bux"
>The standard does not talk about "order of invocation" at all.
It does. For for_each there is this:
Effects:
Applies f to the result of dereferencing every iterator in the range
[first, last), starting from first and proceeding to last - 1.
Also it is stated for the <numericsalgorithms and copy/copy_backward.
Your snipping is really annoying: what you quote is the topic sentence of a
paragraph where I specifically discuss the Effects section of replace_copy
and replace_copy_if. I never intended to make a statement whose scope goes
beyond the particular section under discussion and had you quoted enough,
it would show. Please use a quoting style that avoids making others look
like complete idiots.

[snip]

Best

Kai-Uwe Bux
Oct 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
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:...
6
by: Fraser Ross | last post by:
Algorithms cannot be used with input stream iterators? Is copying the range to a temporary container before using the algorithm the usual thing to do? Fraser.
3
by: monte | last post by:
Hello, I need to parse a tilde delimited file and output it to a tabbed delimited file. Example file example.txt data1~data2~data3~data4 data5~data6~data7~data8 I need to extract data2,...
4
by: cheesywillie | last post by:
How would this be done? For example find every "a" and replace them with a "b". Sorry if i am not being descriptive enough, but i don't know how else to phrase the question. If you need any...
13
by: Hongyu | last post by:
Hi, I have a datetime char string returned from ctime_r, and it is in the format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars including the last terminate char '\0', and i would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.