why is there no std::make_function()?

前端 未结 4 838
夕颜
夕颜 2020-12-16 14:28

std::function<> is a useful wrapper around almost any callable thing, including free functions, lambdas, functors, member functions, results from st

4条回答
  •  爱一瞬间的悲伤
    2020-12-16 14:45

    class multi_functor
    {
      public:
        void operator()(int) { std::cout << "i'm int" << std::endl }
        void operator()(double) { std::cout << "i'm double" << std::endl }
    };
    
    int main(void)
    {
      auto func = make_function(multi_functor());
    }
    

    Because what would be the type of func here ?

    This ambiguity applies to all functor objects (which includes bind return values and lambdas), which would make make_function only usable on function pointers.

提交回复
热议问题