I have a suggestion for the standard library....
This is sort of a combination of std::transform() and std::for_each().
It applies the binary function to each iterator in [start1, end1), to the
corresponding member of the container beginning with start2. Like for_each(),
it returns the functor.
---
template<typename Iter1, typename InIter2, typename BinaryFunc>
BinaryFunc apply(Iter1 start1, Iter1 end1, InIter2 start2, BinaryFunc func)
{
while (start1 != end1)
{
func(*start1, *start2);
++start1;
++start2;
}
return func;
}
---
You could dummy up something like this with for_each() and a clever functor, but
you begin to lose readability. Any comments, suggestions?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ] 3 1664
"red floyd" <no*****@here.dude> wrote in message
news:c5*****************@newssvr29.news.prodigy.co m... I have a suggestion for the standard library....
This is sort of a combination of std::transform() and std::for_each(). It applies the binary function to each iterator in [start1, end1), to the corresponding member of the container beginning with start2. Like
for_each(), it returns the functor.
--- template<typename Iter1, typename InIter2, typename BinaryFunc> BinaryFunc apply(Iter1 start1, Iter1 end1, InIter2 start2, BinaryFunc
func) { while (start1 != end1) { func(*start1, *start2); ++start1; ++start2; } return func; } --- You could dummy up something like this with for_each() and a clever
functor, but you begin to lose readability. Any comments, suggestions?
A number of algorithms in the standard library could be generalized in this
way, to operate on two sequences instead of one, using binary rather than
unary predicates or functions. For instance, one could have a version of
find_if which takes two sequences and a binary predicate.
Instead of introducing double versions of these algorithms, a more general
solution might be to define iterator adaptors which turn pairs of iterators
into iterators over pairs.
Jonathan
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
red floyd wrote: I have a suggestion for the standard library....
This is sort of a combination of std::transform() and std::for_each(). It applies the binary function to each iterator in [start1, end1), to the corresponding member of the container beginning with start2. Like for_each(), it returns the functor.
--- template<typename Iter1, typename InIter2, typename BinaryFunc> BinaryFunc apply(Iter1 start1, Iter1 end1, InIter2 start2, BinaryFunc func) { while (start1 != end1) { func(*start1, *start2); ++start1; ++start2; } return func; } --- You could dummy up something like this with for_each() and a clever functor, but you begin to lose readability. Any comments, suggestions?
How is this different from std::transform, aside from the lack of an
output iterator?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Jeff Schwab wrote: red floyd wrote:
I have a suggestion for the standard library....
This is sort of a combination of std::transform() and std::for_each(). It applies the binary function to each iterator in [start1, end1), to the corresponding member of the container beginning with start2. Like for_each(), it returns the functor.
--- template<typename Iter1, typename InIter2, typename BinaryFunc> BinaryFunc apply(Iter1 start1, Iter1 end1, InIter2 start2, BinaryFunc func) { while (start1 != end1) { func(*start1, *start2); ++start1; ++start2; } return func; } --- You could dummy up something like this with for_each() and a clever functor, but you begin to lose readability. Any comments, suggestions?
How is this different from std::transform, aside from the lack of an output iterator?
transform performs the operation and copies it to the output. the posted
function does the operation "in place", without the overhead of operator=().
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Richard Shea |
last post by:
Hi - Is there a tool available which given a set of PHP scripts will
analyse them and show you which function is called by which other
function ? I'm looking for something which would allow me to...
|
by: Nachi |
last post by:
I am getting 2 resultsets depending on conditon, In the second
conditon i am getting the above error could anyone help me..........
CREATE proc sp_count_AllNewsPapers
@CustomerId int
as...
|
by: Eshrath |
last post by:
Hi,
What I am trying to do:
=======================
I need to form a table in html using the xsl but the table that is
formed is quite long and cannot be viewed in our application. So we
are...
|
by: Albert Wagner |
last post by:
I have a page with two frames. Frame1 contains an inline script. Frame2
contains inline and 2 loaded scripts. How may I call a function in
frame1(inline) from frame2(inline or loaded)?
Albert
|
by: z. f. |
last post by:
Hi,
i'm using code in my aspx page.
i have data binding where i use <%# Container.DataItem("DateStart") %>
i also use code that makes a loop inside a regular
<%
%>
block
how can i pass...
|
by: Simple Simon |
last post by:
Java longs are 8 bytes. I have a Java long that is coming in from
the network, and that represents milliseconds since Epoch (Jan 1 1970
00:00:00). I'm having trouble understanding how to get it...
|
by: Michael |
last post by:
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the...
|
by: -Karl |
last post by:
Couls someone please advise me on this error. What I am trying to do
is be able to convert an XML document into arrays. I read that the
subs & functions have to be in <scripttags.
Thanks!
...
|
by: Rune Allnor |
last post by:
Hi folks.
I have a function that takes an element in a vector as
argument. The naive interface goes as
float computeSomething(const std::vector<float>& v, size_t i)
{
size_t j = i-1;
size_t...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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,...
|
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...
| |