c++ - Is there a way to name a type for a function template specialization? -
For example, when we have a normal function template, we can use the template type in the function: < / P> Now, imagine the attributes of the template in this function: Note that in both of the above mentioned features, I have to specify the type of template logic that The name is special, the functions of functions I prefer to use the more general location holder (i.e., t) rather than being repetitive (typically, at times) within the bodies of template specialties. If a method uses T or the actual specialization function, make a nickname at the point of definition, it would be great, I know that I can do this actual function inside the body through one type of other name. I: I like special conferences that I like: or: Thanks for any advice. Templates & lt; Typename T & gt; Zero foo () {tt; ...}
template & lt; & Gt; Void foo & lt; MySpecialType & gt; () {Tt; // Not compiled, no knowledge of formal template logic T MySpecialType T2; // It's okay, but I have to mention the type of mespecific type} template & lt; & Gt; Void foo & lt; MySpecialType2 & gt; () {Tt; // does not compile, no knowledge of formal template logic T MySpecialType2 t2; // It's ok, but I have to mention the type of type 2 again)
template & lt; & Gt; Void foo & lt; MySpecialType & gt; {T = MySpace Type; // But still I repeat this at least once ...
// Warning: Not valid C ++ template & lt; & Gt; Zero foo & lt; T = MySpecialType & gt; {Tt; ...
// Warning: Valid C ++ template & lt; T & gt; Void foo & lt; MySpecialType & gt; {Tt; ...
You can do something like this:
template & lt ; Typename T & gt; Struct bar {type = T; Static zero foo (); }; Template & lt; Typename T & gt; Zero times & lt; T & gt; :: foo () {type t; // ...} template & lt; & Gt; Zero times & lt; MySpecialType & gt; :: foo () {type t; // ...} template & lt; & Gt; Zero times & lt; MySpecialType2 & gt; :: foo () {type t; // ...} template & lt; Typename T & gt; Zero foo () {bar
But do you really need it?
Comments
Post a Comment