View previous topic :: View next topic |
Author |
Message |
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Sun Jul 23, 2006 2:37 am Post subject: Use of typesafe variadics |
|
|
I just re-read about D's typesafe variadic functions, specifically their behavior when working with classes, and I uncovered a tasty tidbit I had nearly missed. This being, that when a function/method has an arguments signature such as (Foo x ...) where 'Foo' is any class, then the caller may pass either an instance of 'Foo' or any other value(s) (<-- note the optional plural!) matching a constructore of class 'Foo'.
So what does this have to do with Mango? Simple. Maybe we could replace all these:
Code: | class Foo {
this (FilePath fp) { /* stuff */ }
this (char[] fp) { this(new FilePath(fp)); }
} |
With this:
Code: | class Foo {
this (FilePath fp ...) { /* stuff */ }
} |
What do you think? _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Sun Jul 23, 2006 2:19 pm Post subject: |
|
|
hrm ...
I suspect that having the distinct ctors present is notably clearer in terms of what one can legitimately do with a class. I haven't read the doc on this aspect, Chris, but it sounds a bit obfuscated? Maybe not ... |
|
Back to top |
|
|
|