473,387 Members | 1,766 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,387 software developers and data experts.

replace loop with some algo ( std & boost maybe )

Hi all,

I've following loop and i'm interested if there is any algorithm in
stl (i see just for_each with appropriate logical meaning) maybe with
some boost classes which can replace following loop :

vector<UIStlLink*>::iterator iter_stl =
i_bone_fragments.begin();
vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
while (iter_stl != i_bone_fragments.end())
{
UIStlLink * p_stl = *iter_stl;
const MCoordinateSystem & cs = *iter_cs;
TransformObjectTo(p_stl,cs);
++iter_stl;
++iter_cs;
}
ASSERT(iter_cs == i_bone_fragments_to.end());

As for me I would like to see smth like :

vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
for_each(i_bone_fragments.begin(),i_bone_fragments .end(),bind(TransformObjectTo,
_1, *iter_cs++));

, but (*iter_cs++) is computed once as expected.

Thanks
Jan 11 '08 #1
5 1742
yurec wrote:
Hi all,

I've following loop and i'm interested if there is any algorithm in
stl (i see just for_each with appropriate logical meaning) maybe with
some boost classes which can replace following loop :

vector<UIStlLink*>::iterator iter_stl =
i_bone_fragments.begin();
vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
while (iter_stl != i_bone_fragments.end())
{
UIStlLink * p_stl = *iter_stl;
const MCoordinateSystem & cs = *iter_cs;
TransformObjectTo(p_stl,cs);
++iter_stl;
++iter_cs;
}
ASSERT(iter_cs == i_bone_fragments_to.end());

As for me I would like to see smth like :

vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
for_each(i_bone_fragments.begin(),i_bone_fragments .end(),bind(TransformObjectTo,
_1, *iter_cs++));

, but (*iter_cs++) is computed once as expected.
Take a look at 'std::transform'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 11 '08 #2
On Jan 11, 5:45*pm, yurec <Yurij.Zha...@materialise.kiev.uawrote:
Hi all,

I've following loop and i'm interested if there is any algorithm in
stl (i see just for_each with appropriate logical meaning) maybe with
some boost classes which can replace following loop :

vector<UIStlLink*>::iterator iter_stl * * * =
i_bone_fragments.begin();
* vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
* while (iter_stl != i_bone_fragments.end())
* * {
* * UIStlLink * p_stl = *iter_stl;
* * const MCoordinateSystem & cs *= *iter_cs;
* * TransformObjectTo(p_stl,cs);
* * ++iter_stl;
* * ++iter_cs;
* * }
* ASSERT(iter_cs == i_bone_fragments_to.end());

As for me I would like to see smth like :

vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
for_each(i_bone_fragments.begin(),i_bone_fragments .end(),bind(TransformObje*ctTo,
_1, *iter_cs++));

, but (*iter_cs++) is computed once as expected.
You can't do that without a unary functor having
vector<MCoordinateSystem>::const_iterator type as a member which you
initialize upon functor construction and then keep incrementing it
with each call to operator() and applying the logic as in
TransformObje*ctTo. Otherwise, just use transform (the state would not
be needed as it would be a binary functor - probably you can use
TransformObje*ctTo straightaway).
Jan 11 '08 #3
On Jan 11, 4:21*pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
yurec wrote:
Hi all,
I've following loop and i'm interested if there is any algorithm in
stl (i see just for_each with appropriate logical meaning) maybe with
some boost classes which can replace following loop :
vector<UIStlLink*>::iterator iter_stl * * * =
i_bone_fragments.begin();
*vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
*while (iter_stl != i_bone_fragments.end())
* *{
* *UIStlLink * p_stl = *iter_stl;
* *const MCoordinateSystem & cs *= *iter_cs;
* *TransformObjectTo(p_stl,cs);
* *++iter_stl;
* *++iter_cs;
* *}
*ASSERT(iter_cs == i_bone_fragments_to.end());
As for me I would like to see smth like :
vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
for_each(i_bone_fragments.begin(),i_bone_fragments .end(),bind(TransformObje*ctTo,
_1, *iter_cs++));
, but (*iter_cs++) is computed once as expected.

Take a look at 'std::transform'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text-

- Show quoted text -
For my case transform is really good approach.Thank you very much.
I used it in this manner :

transform(i_bone_fragments.begin(),i_bone_fragment s.end(),
i_bone_fragments_to.begin(),i_bone_fragments.begin (),
bind(TransformObjectTo, _1, _2));

Seems to be correct.
However I can imagine situation when should not put result
of transformation into somewhere.And using transform with
binary function I have to put result somewhere, have not I?
Could you suggest another way to solve the task without output
iterator?
Jan 11 '08 #4
On Jan 11, 8:16*pm, yurec <Yurij.Zha...@materialise.kiev.uawrote:
On Jan 11, 4:21*pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:


yurec wrote:
Hi all,
I've following loop and i'm interested if there is any algorithm in
stl (i see just for_each with appropriate logical meaning) maybe with
some boost classes which can replace following loop :
vector<UIStlLink*>::iterator iter_stl * * * =
i_bone_fragments.begin();
*vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
*while (iter_stl != i_bone_fragments.end())
* *{
* *UIStlLink * p_stl = *iter_stl;
* *const MCoordinateSystem & cs *= *iter_cs;
* *TransformObjectTo(p_stl,cs);
* *++iter_stl;
* *++iter_cs;
* *}
*ASSERT(iter_cs == i_bone_fragments_to.end());
As for me I would like to see smth like :
vector<MCoordinateSystem>::const_iterator iter_cs =
i_bone_fragments_to.begin();
for_each(i_bone_fragments.begin(),i_bone_fragments .end(),bind(TransformObje**ctTo,
_1, *iter_cs++));
, but (*iter_cs++) is computed once as expected.
Take a look at 'std::transform'.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask- Hide quoted text -
- Show quoted text -

For my case transform is really good approach.Thank you very much.
I used it in this manner :

transform(i_bone_fragments.begin(),i_bone_fragment s.end(),
* * * * * * i_bone_fragments_to.begin(),i_bone_fragments.begin (),
* * * * * * bind(TransformObjectTo, _1, _2));

Seems to be correct.
However I can imagine situation when should not put result
of transformation into somewhere.And using transform with
binary function I have to put result somewhere, have not I?
Could you suggest another way to solve the task without output
iterator?
Your question is not very clear. That somewhere can be the source
itself (as you have done above), no need to put it somewhere else if
you don't want to. It might be needed when you don't wish to modify
your source though. Will that be a problem for you? This flexibility
is not available with for_each but you can achieve it with a little
pain in the functor.
Jan 11 '08 #5
On Jan 11, 5:27*pm, Abhishek Padmanabh <abhishek.padman...@gmail.com>
wrote:
Your question is not very clear. That somewhere can be the source
itself (as you have done above), no need to put it somewhere else if
you don't want to. It might be needed when you don't wish to modify
your source though. Will that be a problem for you? This flexibility
is not available with for_each but you can achieve it with a little
pain in the functor
As I say for me it's ok to put result into the source, but if I don't
want to
modify the source i will not be able to do the same with such nice (as
for me)
piece of code.

Jan 11 '08 #6

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

Similar topics

10
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x";...
4
by: Arturo Cuebas | last post by:
The program below contains a compile error. Following the program you will find the typical fix then my idea for a library that facilitates a more elegant fix. #include <boost\bind.hpp> using...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
6
by: AzizMandar | last post by:
There is probably a better way to do this and if so I'm just as happy to see that way. I have a program where I have factories that each create various objects abstracted from a base class. ...
3
by: Goran Djuranovic | last post by:
Hi all, I ran into a problem where my XMLTextReader fails on .Read() when I have "<" character in one of the attribute's values. What I am trying to do is replace illegal characters ("<", "&" ,...
0
by: peter | last post by:
Sorry if this is the wrong place to ask but I have just been toying around with boost ad have come across the following:- #include <iostream> #include <boost/regex.hpp> using namespace std; ...
9
by: nguillot | last post by:
Hello I used to loop on a std::map<k, dto act on the data (d) like that (d being a class with setIntMember method): typedef std::map<k, dtMap; struct setIntMember { setIntMember(int j) :...
6
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. There are at least 300 corrections and its expected for this to happen a lot more in the future. Therefore id like a nice...
3
by: Giovanni Gherdovich | last post by:
Hello, in the following code I have a pointer (to function), say p, of type double (*)(double, double, void*) and I try to fix the second argument of the function *p to a given value (using...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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:
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...
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
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.