On Thu, 2017-04-06 at 11:45 -0700, Ali Çehreli via Digitalmars-d-learn wrote: > […] > I think it's just a design choice. C implicitly converts the name of > the > function to a pointer to that function. D requires the explicit & > operator:
One of the dangers of being a bit like and a replacement for another
language is that often people carry ideas over incorrectly, as I have
here.
> alias Func = int function(int);
>
> int foo(int i) {
> return i;
> }
>
> void main() {
> Func[] funcs = [ &foo ];
> }
I just did:
immutable funcs = [tuple(&foo, "foo")];
as I don't need the name of the type, but I do need a string form of
the name of the function.
> Close to what you mentioned, name of the function can be used as an
> alias template parameter:
>
> void bar(alias func)() {
> func(42);
> }
>
> int foo(int i) {
> return i;
> }
>
> void main() {
> bar!foo();
> }
Good to know but for situation here the &foo was what was needed.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:[email protected]
41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected]
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part
