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 Struct abs_helper {static t abs (T const value) {return std :: abs ( Values); }}; Template & lt; Typename T & gt; Structure Ab_helper & lt; Vector 2 & lt; T & gt; & Gt; {Static vectors 2 & lt; T & gt; Ab (general :: vector 2 <> element & matrix) {return matrix.abs (); }}; Template & lt; Typename T & gt; Auto Abuse (T & amp; Price) - & gt; Decltype (abs_helper & lt; std :: removal_const_t & lt; std :: remove_reference_t & lt; t & gt; & gt; :: stomach (std is ahead & lt :: t> (value))) {Return abs_helper & lt; Std :: removal_const_t & lt; Std :: removal_reference_t & lt; T & gt; & Gt; & Gt; :: The stomach (std is ahead & lt :: t> (value)); }

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:

  1. struct abs_helper is a class template that is partly specific May be partially and may be vector 2
  2. Function template abs () function template
  3. just 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:
  4. Template argument for 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 C ++ 14 Type signs have been removed after using Remove_const & lt; T & gt; ).
  5. The return type looks different depending on the actual call to work using the code by using decltype () using the code to determine the type C ++ 11 Returns -Type specification uses

Comments