New to D: parse a binary file
Mafi
mafi at example.org
Sun Feb 6 14:05:01 PST 2011
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
More information about the Digitalmars-d-learn
mailing list