473,385 Members | 2,004 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,385 software developers and data experts.

Loki's Visitor and for_each

I do this kindda stuff often:

class CVisitableObjectVector : public
std::vector<Loki::BaseVisitable<>*> {

void Enable(bool enable);
....
};
void CVisitableObjectVector::Enable(bool enable) {

CLokiVisitor Visitor(enable);

CVisitableObjectVector::iterator i = begin();

for (; i != end(); i++) {
(*i)->Accept(Visitor);
}

}

Can that for(;;;) loop be replaced with the std::for_each algorithm?

I've tried with no success. I've used ptr_fun, mem_fun etc.. Nothing
works. Has anyone out there done this?

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 22 '05 #1
1 1959
Maybe something like this - sorry, don't have time to compile it and try it:
#include<function>
#include<algorithm>

using namespace std; // just to keep example short
for_each( begin(),
end(),
bind2nd( mem_fun1_t<CVisitableObjectVector,CLokiVisitor>(
Accept ), Visitor ) );
The idea is, you want the mem_fun1_t because you want to call a member
function via a pointer, and it takes one argument. However, since
for_each passes only the container element to the member function (or
functor) you use bind2nd to bind the Visitor to a functor first... Or
some such...
tr***@primarykeydevelopment.com wrote:
I do this kindda stuff often:

class CVisitableObjectVector : public
std::vector<Loki::BaseVisitable<>*> {

void Enable(bool enable);
...
};
void CVisitableObjectVector::Enable(bool enable) {

CLokiVisitor Visitor(enable);

CVisitableObjectVector::iterator i = begin();

for (; i != end(); i++) {
(*i)->Accept(Visitor);
}

}

Can that for(;;;) loop be replaced with the std::for_each algorithm?

I've tried with no success. I've used ptr_fun, mem_fun etc.. Nothing
works. Has anyone out there done this?

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Jul 22 '05 #2

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

Similar topics

5
by: Alex Vinokur | last post by:
Functor-parameters in the for_each() and transform() algorithms are passed by value. Might it make sense to have also algorithms for_each2() and transform2() which pass Functor-parameters by...
0
by: Sebastian Faust | last post by:
Hi, I read about the Loki::Factory and Loki::AbstractFactory in the book Modern C++ Design and couldnt figure out one thing: If I have several classes, for example the following hierarchie: ...
1
by: Dave | last post by:
Is anybody aware of a newsgroup devoted to Loki? I assume this forum would not be the most appropriate place to discuss a specific library, even if that library is written purely in standard...
3
by: Krivenok Dmitry | last post by:
I writing simple class CmdLine: ..... ..... class CmdLine { ..... ..... public: /// Constructor CmdLine(int argc, char** argv);
3
by: Krivenok Dmitry | last post by:
Hello All! This is example of code: ////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef A_H_ #define A_H_ #include <Loki/Singleton.h>...
2
by: Martin Herbert Dietze | last post by:
Hi, in a project I am using callbacks which are called like ordinary functions but in fact are Loki::Functor's encapsulating calls to non-static member functions on instances of different...
10
by: Ray | last post by:
I am reading Andrei Alexandrescu's book. The ideas presented there sound really good, but I wonder--is there really a lot of people using it? Or it's simply too esoteric for mortals? Cheers Ray
2
by: Shawn McGrath | last post by:
Hey, I can't get DeletableSingleton to actually delete the singleton. The code is: typedef Loki::SingletonHolder<GenClass Loki::CreateUsingNew, Loki::DeletableSingletonGen; .......
3
by: aaragon | last post by:
Hello everyone, I've been trying to work with the visitor design pattern, and it works fine except for the following. Let's suppose that we have a fixed hierarchy of classes (many of them)...
0
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,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
0
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,...
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.