I have implemented the following class (simplified ;) )

----
class Foo(K,T) {
    this(T delegate (K) factory) { m_factory = factory; }
    T delegate (K) m_factory;
    T bar(K key) { return m_factory(key); }
}

string dummyFactory(string key) { return "Hello "~key; }

void main()
{
    auto foo = new Foo!(string,string)(&dummyFactory);
    writeln(foo.bar("world"));
}
----

The compiler complains that dummyFactory is a pointer to a function and not a delegate. How can I modify the class definition so that it accepts a function or a delegate transparently from the user perspective ?

Two constructors, one accepting a function and the other one accepting a delegate would do the job for the API. Is there a simple method to convert a function pointer into a delegate pointer that is also efficient ?

Reply via email to