Can't understand templates
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat Nov 29 00:06:32 PST 2014
    
    
  
On 11/28/2014 10:26 PM, Sly wrote:
 > I still don't understand how to
 > read this signature:
 > Point!T getResponse(T: Point!T)(string question)
The following is what makes sense to me.
Sorry for going step by step but I think it helped me understand your 
question. (See item 3 below.)
1) Point!T is the return type. Although T is unknown at this point, we 
will wait a little because it may be a template parameter.
Also, according to the syntax of Point!T, Point is apparently a 
template. So, this function will return the T instantiation of Point, 
whatever T will be deduced to be in a moment.
2) getResponse is the name of the function
3) The first set of parameters is the template parameters:
(T: Point!T)
The meaning: T is a type and this specialization is for Point!T.
Ok, I think I finally understand your original question. I agree that it 
doesn't make sense to say "T is a type and this specialization is for 
Point!T". I think we need to read it backward in this case: "This 
specialization is for Point!T. If so, deduce T from that." So, if 
getResponse is instantiated with Point!int, then T is deduced to be int.
4) The instances of this function template take string parameter.
Ali
    
    
More information about the Digitalmars-d-learn
mailing list