C++ - Specialize member function for Template Class -
I have a class-template representing the mathematical vector:
Lt; class Value_T, unsigned int N & gt; Square vector (public: zero normal) () {// normal liver only to double / float vectors} Personal: vector value_type elements [n] in element:; // Number of elements fixed constant size = N; }; I have to make a special treatment for the whole type of vectors because vector generalization is not possible on this type. So I can have a separate (specialization) for the generalized method which is based on the template graph VectorT class-template's Value_T
I have tried to use the template specialization in different ways, But it did not get to work. Do I have to work a template function normally? At the moment it is just an normal member-method.
You can solve this with an tag sending technique: #include & lt; Iostream & gt; # Include & lt; Type_traits & gt; Template & lt; Class Value_T, unsigned int N & gt; Square vector {public: zero normal () {tag = std :: integral_constant & lt; bool, std :: is_same & lt; Value_T, double & gt; :: using value || Std :: is_same & lt; Value_T, float & gt; :: value & gt ;; // Generally normalize only double / float vectors (tag); } Private: zero generalized (standard :: true_type) {std :: cout & lt; & Lt; "Generalized" & lt; & Lt; Std :: endl; } Zero general (std :: false_type) {std :: cout & lt; & Lt; "Not normal" & lt; & Lt; Std :: endl; } // Vector value element in element [n] in meteite elements; // Number of elements fixed static std :: size_t size = N; };
Comments
Post a Comment