Discussion:
List of closures
(too old to reply)
Peter Hull
2008-06-20 07:48:16 UTC
Permalink
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
Peter Hull
2008-06-30 11:17:04 UTC
Permalink
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
Post by Peter Hull
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*
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
Loading...