Deduce template argument from std::function call signature

前端 未结 3 1128
北荒
北荒 2020-11-27 22:10

Consider this template function:

template
ReturnT foo(const std::function& fun)
{
    return fun();
}
         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 23:07

    The function bar is of type bool (*)() or so, that is: a normal pre-C++11 function type. I'm not that confident in C++11, but I guess the compiler does not see the connection between bool (*)() and const std::function&, even when the first can be implicitly converted into the second for ReturnT = bool.

提交回复
热议问题