Get argument type of template callable object

后端 未结 4 1544
不知归路
不知归路 2020-12-09 04:33

Consider the following function:

template
void register_handler( F& f ) // any callable object
{
   // find out T - the argument type of f         


        
4条回答
  •  轮回少年
    2020-12-09 04:54

    if F is a std::functionyou should be able to use the its member type and check with `std::is_same':

    template
    void register_handler( F& f ) // any callable object
    {
       // find out T - the argument type of f
       if(std::is_same::value)
       { .... }
       //etc .....
    
    }
    

    An up and running example here

    but that kind of code can quickly become a mess to maintain.

提交回复
热议问题