How to make template parameter

后端 未结 2 927
情书的邮戳
情书的邮戳 2021-01-15 19:14

How do I create a metafunction that takes any kind of function pointer? In the code below, how do I get rid of \"decltype(&f)\" ?

template 

        
相关标签:
2条回答
  • 2021-01-15 19:39

    Right now there is unfortunately no good way of doing this.

    The standard committee has, however, accepted a proposal that makes this valid code:

    template <auto functionPointer>
    void runFunc() {
      functionPointer();
    }
    

    Compiler support should be coming soon.

    0 讨论(0)
  • 2021-01-15 19:45

    You can use this:

    template <typename FuncType>
    void runFunc(FuncType functionPointer )
    {
        functionPointer();
    }
    
    runFunc(f);
    
    0 讨论(0)
提交回复
热议问题