c++ - How to write template specialization for only SOME of the parameters needed to implement the template -
I have a straightener called vector 2, which contains the template parameters of t
(vector2.h )
template & lt; Typename T & gt; Structure vector 2 {t value [2]; // ..... Method .....};
I have a method called ABS that is the cover of the std :: abs () function for most types (this may seem strange, but for clarifying my question Please nude with me)
(mymath.h)
Template's & lt; Typename t & gt; Static T Stomach (Const T Value) {return std :: abs & lt; T & gt; (Values); }
If I try the vector 2 string for the abs and do not pass it then this will not work because the template specification used in STD does not include a method for this ... obviously, I have made it :)
I want to make one.
How can I create a template specialization for a method that takes a structure that requires its template parameters?
This was my best guess, but this is not a valid syntax. Is this possible?
(mymath.cpp)
template & lt; Typename T & gt; Static vector 2 & lt; T & gt; Stomach & lt; Vector 2 & lt; T & gt; & Gt; (Constrict vector 2 & gt; & gt; and vector) {return vector.abs (); // it exists)
The function template can only be completely unique Function templates can not be partially specialists However, you The forwarding is that your code uses different approaches to pass logic for two different functions, given a bit complex: the code tries to mimick this forward (i Have not attempted to compile it). Just to understand a bit of what is happening:
struct abs_helper
is a class template that is partly specific May be partially and may be vector 2
abs ()
function template abs_helper & lt; ... & gt; :: abs (...)
next to Since it makes its logic forward, it uses prefet for forwarding. There are complexities with this forwarding, however: abs ()
is an estimate in which a reference and / or const
can be It must be removed before sending on special abs_helper
(otherwise it will require many specializations). T & gt; and std :: In this way, replace any other
constant
in any reference ( std :: removal_reference_t using
). decltype ()
using the code to determine the type C ++ 11 Returns -Type specification uses
Comments
Post a Comment