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> Templates & lt; Typename T & gt; Zero foo () {tt; ...}

Now, imagine the attributes of the template in this function:

  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)  

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:

  template & lt; & Gt; Void foo & lt; MySpecialType & gt; {T = MySpace Type; // But still I repeat this at least once ...  

I like special conferences that I like:

  // Warning: Not valid C ++ template & lt; & Gt; Zero foo & lt; T = MySpecialType & gt; {Tt; ...  

or:

  // Warning: Valid C ++ template & lt; T & gt; Void foo & lt; MySpecialType & gt; {Tt; ...  

Thanks for any advice.

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

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -