Expression SFINAE to overload on type of passed function pointer

后端 未结 2 493
一生所求
一生所求 2021-01-18 06:47

In this example a function is passed to an implicitly instantiated function template.

// Function that will be passed as argument
int foo() { return 0; }

//         


        
2条回答
  •  别那么骄傲
    2021-01-18 07:50

    The closest you can get is probably this:

    struct sfoo
    {
      template
      void operator() (args&&... a)
      { 
        foo(std::forward(a)...);
      }
    };
    

    and pass sfoo (or sfoo()) instead of foo around.

    That is, create a function object type that encapsulates the entire overload set in the templatized operator().

    Then instead of overload resolution over a template argument, which does not exist, you get a template instantiation over the same argument, which is OK.

提交回复
热议问题