I bought "The D Programming Language" a little while ago. Great book, very educational. However I'm having trouble trying to compile a language feature listed in the book: Extension Functions.
In the book, Andrei writes any function(a, b) can be invoked like: a.function(b); So I should be able to do this:
struct Person {
string name;
}
void foo(Person person, string name) {
person.name = name;
}
void main() {
auto bob = Person();
bob.foo("Bob Dole"); // ERROR: Person does not have method 'foo'
}
Correct? Is this feature not implemented yet, or am I just missing something? I notice that importing std.range adds methods to arrays so it does appear t开发者_C百科o be implemented at some level.
I take it you mean "Psuedo Members" as talked about in section 5.9.1. Currently this feature is only implemented for arrays, though this is a planned feature. In the D community you will also see it referred to as "Uniform Function Call Syntax."
Here's the bug report which will be closed when this feature is implemented: Issue 3382
Just wanted to state, that Uniform Function Call Syntax has been implemented.
There is a nice Dr. Dobbs article about it: Uniform Function Call Syntax on Dr. Dobbs
精彩评论