June 02, 2012 DMD does not allow stringof on function alias of a function that takes arguments | ||||
|---|---|---|---|---|
| ||||
Attachments:
| Greetings All
Using DMD 2.059, the following code does not compile. DMD does not allow me to apply stringof on a function alias of a function that takes one or more arguments. It compiles and runs fine for functions that do not take any arguments.
Is it a bug, or am I doing something wrong here?
Regards
- Puneet
class Foo {
void foo() { }
void frop(int n) { }
}
void callfoo(alias F, T) (T t) {
import std.stdio;
writeln(F.stringof);
}
void main() {
Foo f = new Foo();
callfoo!(Foo.foo)(f); // This works
callfoo!(Foo.frop)(f); // This does not work
}
| |||
June 02, 2012 Re: DMD does not allow stringof on function alias of a function that takes arguments | ||||
|---|---|---|---|---|
| ||||
Posted in reply to d coder | On 2012-06-02 13:40, d coder wrote: > Greetings All > > Using DMD 2.059, the following code does not compile. DMD does not allow > me to apply stringof on a function alias of a function that takes one or > more arguments. It compiles and runs fine for functions that do not take > any arguments. > > Is it a bug, or am I doing something wrong here? > > Regards > - Puneet > > class Foo { > void foo() { } > void frop(int n) { } > } > > void callfoo(alias F, T) (T t) { > import std.stdio; > writeln(F.stringof); > } > > void main() { > Foo f = new Foo(); > callfoo!(Foo.foo)(f); // This works > callfoo!(Foo.frop)(f); // This does not work > } > I'm guessing that the problem is that you can call a function without parentheses in D (this is how properties are implemented). So the problem is that it will actually try and call the function with no arguments, which will fail since it expects, in this case, an int. Try taking the address of the function first: writeln(&F.stringof); -- /Jacob Carlborg | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply