473,698 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loki's Visitor and for_each

I do this kindda stuff often:

class CVisitableObjec tVector : public
std::vector<Lok i::BaseVisitabl e<>*> {

void Enable(bool enable);
....
};
void CVisitableObjec tVector::Enable (bool enable) {

CLokiVisitor Visitor(enable) ;

CVisitableObjec tVector::iterat or 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 1970
Maybe something like this - sorry, don't have time to compile it and try it:
#include<functi on>
#include<algori thm>

using namespace std; // just to keep example short
for_each( begin(),
end(),
bind2nd( mem_fun1_t<CVis itableObjectVec tor,CLokiVisito r>(
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***@primaryke ydevelopment.co m wrote:
I do this kindda stuff often:

class CVisitableObjec tVector : public
std::vector<Lok i::BaseVisitabl e<>*> {

void Enable(bool enable);
...
};
void CVisitableObjec tVector::Enable (bool enable) {

CLokiVisitor Visitor(enable) ;

CVisitableObjec tVector::iterat or 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
4672
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 non-const reference? Here is some program which demonstrates probable necessity in such forms of for_each() and transform().
0
2832
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: clase Base { public: Base(Base* pBase) : _pBase(pBase) { }
1
2925
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 C++... (well, almost true of Loki, except for threads...)
3
2233
by: Krivenok Dmitry | last post by:
I writing simple class CmdLine: ..... ..... class CmdLine { ..... ..... public: /// Constructor CmdLine(int argc, char** argv);
3
4592
by: Krivenok Dmitry | last post by:
Hello All! This is example of code: ////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef A_H_ #define A_H_ #include <Loki/Singleton.h> #include <Loki/SmartPtr.h> #include <iostream>
2
4022
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 classes. The approach using Loki::Functor looks like this: | class X {
10
2946
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
2213
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; .... Gen::Instance(); .... Loki::DeletableSingleton<Gen>::GracefulDelete();
3
2308
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) which I cannot modify. I decided to use the visitor design pattern depending on the actual type of the classes because those classes already support the loki visitor. #include <Loki/Visitor.h>
0
8683
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
8611
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
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
6531
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
5867
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();...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.