February 06, 2011 Re: New to D: parse a binary file | ||||
---|---|---|---|---|
| ||||
scottrick Wrote:
> T[] rawRead(T)(T[] buffer);
>
> I understand that T is generic type, but I am not sure of the meaning of the (T) after the method name.
That T is defining the symbol to represent the generic type. It can have more than one and D provides other things like aliases... Another way to write that function (I may get something wrong here but give it a shot) is:
template(T) {
T[] rawRead(T[] buffer);
}
|
February 06, 2011 Re: New to D: parse a binary file | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | Am 06.02.2011 19:38, schrieb Jesse Phillips: > scottrick Wrote: > >> T[] rawRead(T)(T[] buffer); >> >> I understand that T is generic type, but I am not sure of the >> meaning of the (T) after the method name. > > That T is defining the symbol to represent the generic type. It can have more than one and D provides other things like aliases... Another way to write that function (I may get something wrong here but give it a shot) is: > > template(T) { > T[] rawRead(T[] buffer); > } I think you meant template(T) rawRead{ T[] rawRead(T[] buffer); } 'template' defines a namespace which is normally accessed like templ!(parameters).member; templ!(parameters).memberfunc(parameters); Because the template and it's member are called identically this member is accessed autoatically (the eponymous-trick). If it's a function you call it like that: templfunc!(compiletimeparam)(param); The compile time parameters can left out, if these can be derived from the normal parameters' type. templfun(param); Voilla! You have a completely transparent templated func. Mafi |
Copyright © 1999-2021 by the D Language Foundation