Board index » cppbuilder » List of closures

List of closures


2008-06-20 03:48:16 PM
cppbuilder34
What's the best way to add closures to a list?
I've got some code like this
typedef void (__closure *NotifyFunc)(AnsiString);
...
TList* notifier_list;
...
void AddNotifier(NotifyFunc nf)
{
notifier_list->Add((void*) nf);
}
But I get an error because it cannot convert NotifyFunc to void*
I can get round it with a wrapper:
struct Wrapper {
Wrapper(NotifyFunc _nf) : nf(_nf) {}
NotifyFunc nf;
};
...
void AddNotifier(NotifyFunc nf)
{
notifier_list->Add(new Wrapper(nf));
}
Or I can use std::list<NotifyFunc>
But is there a better way?
Pete
 
 

Re:List of closures

I wonder if anyone has had any thoughts on this, or is my question not
clear or am I asking in the wrong place?
Pete
On Jun 20, 8:48 am, Peter Hull < XXXX@XXXXX.COM >wrote:
Quote
What's the best way to add closures to a list?
I've got some code like this
typedef void (__closure *NotifyFunc)(AnsiString);
...
TList* notifier_list;
...
void AddNotifier(NotifyFunc nf)
{
 notifier_list->Add((void*) nf);}

But I get an error because it cannot convert NotifyFunc to void*

I can get round it with a wrapper:

struct Wrapper {
 Wrapper(NotifyFunc _nf) : nf(_nf) {}
 NotifyFunc nf;};

...
void AddNotifier(NotifyFunc nf)
{
 notifier_list->Add(new Wrapper(nf));

}

Or I can use std::list<NotifyFunc>

But is there a better way?

Pete