A variadic template method to accept a given number of doubles?

后端 未结 2 1961
南方客
南方客 2021-02-05 19:06
template  class myclass
{
public:
    template  void mymethod(Args... args)
    {
       // Do interesting stuff
    } 
};
         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 20:02

    Can try something like following :

    #include 
    
    template
    struct all_same : std::true_type
    {};
    
    template
    struct all_same
        : std::integral_constant{} && all_same{}>
    {};
    
    
    template  class myclass
    {
        public:
        template 
         typename std::enable_if::type mymethod(Args... args)
        {
            static_assert(all_same{}, 
                          "Not all args as Double");
        }
    };
    

提交回复
热议问题