www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: New to D: parse a binary file

reply Jesse Phillips <jessekphillips+D gmail.com> writes:
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); }
Feb 06 2011
parent Mafi <mafi example.org> writes:
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); }

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
Feb 06 2011