FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Use of typesafe variadics

 
Post new topic   Reply to topic     Forum Index -> Mango
View previous topic :: View next topic  
Author Message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Sun Jul 23, 2006 2:37 am    Post subject: Use of typesafe variadics Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sun Jul 23, 2006 2:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Mango All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group