473,671 Members | 2,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<UIStlLin k*>::iterator iter_stl =
i_bone_fragment s.begin();
vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
while (iter_stl != i_bone_fragment s.end())
{
UIStlLink * p_stl = *iter_stl;
const MCoordinateSyst em & cs = *iter_cs;
TransformObject To(p_stl,cs);
++iter_stl;
++iter_cs;
}
ASSERT(iter_cs == i_bone_fragment s_to.end());

As for me I would like to see smth like :

vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
for_each(i_bone _fragments.begi n(),i_bone_frag ments.end(),bin d(TransformObje ctTo,
_1, *iter_cs++));

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

Thanks
Jan 11 '08 #1
5 1750
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<UIStlLin k*>::iterator iter_stl =
i_bone_fragment s.begin();
vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
while (iter_stl != i_bone_fragment s.end())
{
UIStlLink * p_stl = *iter_stl;
const MCoordinateSyst em & cs = *iter_cs;
TransformObject To(p_stl,cs);
++iter_stl;
++iter_cs;
}
ASSERT(iter_cs == i_bone_fragment s_to.end());

As for me I would like to see smth like :

vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
for_each(i_bone _fragments.begi n(),i_bone_frag ments.end(),bin d(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
Jan 11 '08 #2
On Jan 11, 5:45*pm, yurec <Yurij.Zha...@m aterialise.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<UIStlLin k*>::iterator iter_stl * * * =
i_bone_fragment s.begin();
* vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
* while (iter_stl != i_bone_fragment s.end())
* * {
* * UIStlLink * p_stl = *iter_stl;
* * const MCoordinateSyst em & cs *= *iter_cs;
* * TransformObject To(p_stl,cs);
* * ++iter_stl;
* * ++iter_cs;
* * }
* ASSERT(iter_cs == i_bone_fragment s_to.end());

As for me I would like to see smth like :

vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
for_each(i_bone _fragments.begi n(),i_bone_frag ments.end(),bin d(TransformObje *ctTo,
_1, *iter_cs++));

, but (*iter_cs++) is computed once as expected.
You can't do that without a unary functor having
vector<MCoordin ateSystem>::con st_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*c tTo. Otherwise, just use transform (the state would not
be needed as it would be a binary functor - probably you can use
TransformObje*c tTo straightaway).
Jan 11 '08 #3
On Jan 11, 4:21*pm, "Victor Bazarov" <v.Abaza...@com Acast.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<UIStlLin k*>::iterator iter_stl * * * =
i_bone_fragment s.begin();
*vector<MCoordi nateSystem>::co nst_iterator iter_cs =
i_bone_fragment s_to.begin();
*while (iter_stl != i_bone_fragment s.end())
* *{
* *UIStlLink * p_stl = *iter_stl;
* *const MCoordinateSyst em & cs *= *iter_cs;
* *TransformObjec tTo(p_stl,cs);
* *++iter_stl;
* *++iter_cs;
* *}
*ASSERT(iter_cs == i_bone_fragment s_to.end());
As for me I would like to see smth like :
vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
for_each(i_bone _fragments.begi n(),i_bone_frag ments.end(),bin d(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_bon e_fragments.beg in(),i_bone_fra gments.end(),
i_bone_fragment s_to.begin(),i_ bone_fragments. begin(),
bind(TransformO bjectTo, _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...@m aterialise.kiev .uawrote:
On Jan 11, 4:21*pm, "Victor Bazarov" <v.Abaza...@com Acast.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<UIStlLin k*>::iterator iter_stl * * * =
i_bone_fragment s.begin();
*vector<MCoordi nateSystem>::co nst_iterator iter_cs =
i_bone_fragment s_to.begin();
*while (iter_stl != i_bone_fragment s.end())
* *{
* *UIStlLink * p_stl = *iter_stl;
* *const MCoordinateSyst em & cs *= *iter_cs;
* *TransformObjec tTo(p_stl,cs);
* *++iter_stl;
* *++iter_cs;
* *}
*ASSERT(iter_cs == i_bone_fragment s_to.end());
As for me I would like to see smth like :
vector<MCoordin ateSystem>::con st_iterator iter_cs =
i_bone_fragment s_to.begin();
for_each(i_bone _fragments.begi n(),i_bone_frag ments.end(),bin d(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_bon e_fragments.beg in(),i_bone_fra gments.end(),
* * * * * * i_bone_fragment s_to.begin(),i_ bone_fragments. begin(),
* * * * * * bind(TransformO bjectTo, _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.padma n...@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
3132
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"; char search = '?'; char* replace = "***"; char* result = search_and_replace(source,search,replace);
4
2728
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 namespace boost; struct C {
8
4032
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 problems getting my algorithm to work and in order to help me find the solution I decided to print each line to screen as I read them. Then, to my surprise, I noticed that there was a space between every character as I outputted the lines to the...
6
2033
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. The Factories all have a base class as well for the objects to point back to. So I have
3
3312
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 ("<", "&" , etc.) with legal stuff ("&lt;", "&amp;", etc.), before I send the XML text to a SQL Server stored procedure. Currently, I am using XMLTextReader and StringWriter to do this, here is the piece of code that fails:...
0
1043
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; void testSearch(const boost::regex &ex, const string st) { cout << "Searching " << st << endl;
9
4003
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) : i(j) {}
6
2228
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 button that does this all for me. In my head the method should go something like this:
3
3332
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 boost::bind), but the compiler complains, because of a type mismatch in an assignment which I think should be legal:
0
8472
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8596
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.