digitalmars.D - An default values for generics
- goodwin (21/21) Jan 23 2013 Hello everybody.
- Adam D. Ruppe (3/3) Jan 23 2013 I think
- goodwin (2/5) Jan 23 2013
Hello everybody.
I started to study the D programming language and i write same
small library which use templates(generics) active. So i have one
question, how can i get default value for template(generic)? May
be something like this:
T someMethod(T)(bool someCondition){
if (someCondition) {
// ... do something and return result
} else {
return default(T);
}
}
I solved this problem with help small hack:
T getDefaultValue(T)(){
T default_value;
return default_value;
}
But i don't like this solution and i don't sure that it is work
in all cases. I want to use standard mechanism if it is exist.
With best regards.
PS: Sorry for my bad english. =)
Jan 23 2013
I think return T.init; will do what you want most easily.
Jan 23 2013
Thanks, this is what i need. On Thursday, 24 January 2013 at 02:11:37 UTC, Adam D. Ruppe wrote:I think return T.init; will do what you want most easily.
Jan 23 2013








"goodwin" <artem.3a gmail.com>