Call a functor with a specific function from an overload set

前端 未结 2 1960
萌比男神i
萌比男神i 2021-01-13 10:50

Context

In mathematics-related context, I\'d like to define functors working on functions. For the purpose of this question, we will be

2条回答
  •  孤独总比滥情好
    2021-01-13 10:52

    How could I name a specific function from an overload set?

    static_cast. E.g.

    std::invoke(static_cast< double(*)(double) >( &std::sin ), 0.0);
    

    There are easier ways to do around this, e.g. use a generic lambda to avoid that horrible syntax:

    std::invoke([](auto x){ return std::sin(x); }, 0.0);
    

    In Qt we've been bit pretty hard by the problem of taking the address of overloaded functions up to the point that helpers have been introduced. I discussed a possible implementation of such a helper here.

    Normative reference for the static_cast usage is here.

提交回复
热议问题