473,574 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MultiFunctor implementation trouble

Hello all!

I want to implement MultiFunctor class.
Consider the following example:

// MultiFunctor object
MultiFunctor<vo id (int, string)> mf;
// Type of MultiFunctor's content
typedef Functor<void (int,string)> Func_t;
// Functors
Func_t f1(&some_func);
Func_t f2(some_functor );
Func_t f3(&som_obj, &SomeClass::Som eMemberFunction );
// Add functors
mf+=f1;
mf+=f2;
mf+=f3;
// Call ALL functors
mf(100,"Hello World"); // Calls all functors
// Delete one functor
mf-=f2;
// Call f1 and f3
mf(200,"Only f1 and f3");

It's fine!

But there is a big problem - how to implement operator -=?

template <class T>
MultiFunctor& MultiFunctor::o perator -=(const T& functor )
{
typedef SomeContainer:: iterator IT;
for(IT i = container_.begi n(); i!=container_.e nd();++i)
{
if( *i == functor) // !!! Main problem is here !!!
{
container_.eras e(i);
break; // Supposing there are not duplicates in container
}
}
return *this;
}

The main question:
Is there a way to compare two functors???

Thanks!

P.S.
I know about another approach:

ID_t id1 = mf.add(f1);
ID_t id2 = mf.add(f2);
ID_t id3 = mf.add(f3);
mf(1000,"Bad solution"); // Calls f1,f2,f3
mf.delete(id2);
mf(1000,"Bad solution"); // Calls f1,f3

But it's a ugly hack :(

Jun 5 '06 #1
1 1502
Krivenok Dmitry wrote:
I want to implement MultiFunctor class.
Consider the following example:

// MultiFunctor object
MultiFunctor<vo id (int, string)> mf;
// Type of MultiFunctor's content
typedef Functor<void (int,string)> Func_t;
// Functors
Func_t f1(&some_func);
Func_t f2(some_functor );
Func_t f3(&som_obj, &SomeClass::Som eMemberFunction );
// Add functors
mf+=f1;
mf+=f2;
mf+=f3;
// Call ALL functors
mf(100,"Hello World"); // Calls all functors
// Delete one functor
mf-=f2;
// Call f1 and f3
mf(200,"Only f1 and f3");

It's fine!
Does that mean you have implemented it already?
But there is a big problem - how to implement operator -=?

template <class T>
MultiFunctor& MultiFunctor::o perator -=(const T& functor )
{
typedef SomeContainer:: iterator IT;
for(IT i = container_.begi n(); i!=container_.e nd();++i)
{
if( *i == functor) // !!! Main problem is here !!!
{
container_.eras e(i);
break; // Supposing there are not duplicates in container
}
}
return *this;
}

The main question:
Is there a way to compare two functors???
Well, if you managed to stuff them in the same class (you named it
'Func_t'), what is stopping you from comparing two objects of the
same type? Equality is very simple. Use member-wise comparison
semantics. The compiler doesn't implement one for you, I know, but
that shouldn't concern you. Just like you should be able to assign
(by using member-wise assignment semantics), there is nothing to
equality. Just add one more equal sign.
[..]


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 5 '06 #2

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

Similar topics

2
4525
by: Will Oram | last post by:
Normally I use PB for Cocoa, but now I'm using it for a school project. I have an implementation file, a header, and a main cpp file. I have a class defined in the header, which I will simplify to the basics for viewing audiences: class SomeClass { public: SomeClass(); //constructor };
2
1505
by: Matt | last post by:
For example, we want to produce a new language called NewLang. When we implement the compiler of NewLang, we should use languages other than NewLang. Correct? But I heard Java is implemented in C/C++. More specifically, does it mean the Java compiler is written in C/C++? But the Java API is written in Java itself. This is the confusing...
0
1374
by: ma740988 | last post by:
Puzzled about an implementation here. In a vendor file, I'm faced: // vendors_file.h #ifdef __cplusplus typedef void (*VOIDFUNCPTR) (...); /* pfunction returning void */ #else typedef void (*VOIDFUNCPTR) (); /* pfunction returning void */ #endif /* __cplusplus */
27
1928
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the <Serialized()> attribute on the class and away you go. As Homer would say - "D'Oh" The root of my problem lies in the way VB implements Events and the fact...
110
8523
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm almost halfway through writing the over 200 functions needed to implement C99's version of math.h, and I would like to have some feedback and/or...
27
1998
by: stonemcstone | last post by:
I've been programming in C for years, and never experienced troubles until I started using the new RealC-32, a freeware C compiler from the same company that makes RealPlayer and Quicktime. That's when the trouble started. See, RealC-32 is like any other C compiler but with one notable difference. Any time your code invokes undefined...
4
1043
by: mijalko | last post by:
Look at this code: class test { private bool bInitialized = false; private string strTest; public string str2 = ""; private void Init() { if (bInitialized)
39
3530
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody out there understands what happens. Essentially, when I subtract the (double) function value GRID_POINT(2) from a variable which has been assigned...
5
13333
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the...
0
7794
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...
0
7710
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...
0
8225
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...
1
7800
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...
0
8092
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...
0
6437
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...
0
3738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
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

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.