Specializing function template for reference types

后端 未结 3 1785
南旧
南旧 2020-12-19 00:46

Why is the output of this code :

#include   
template void f(T param) 
{ 
   std::cout << \"General\" << std::e         


        
3条回答
  •  清酒与你
    2020-12-19 00:53

    I know it is not answer but, IMHO you can try this, with a trait like approach in a struct:

    template
    struct value_traits
    {
        static void print(){std::cout << "General" << std::endl ;} 
    };
    
    template<>
    struct value_traits
    {
        static void print(){std::cout << "const long" << std::endl ;} 
    };
    
    template<>
    struct value_traits >
    {
        static void print(){std::cout << "std::vector" << std::endl ; }
    };
    
    template<>
    struct value_traits
    {
           static void print(){std::cout << "const int" << std::endl ;} 
    };
    

提交回复
热议问题