Явно указав тип обратного возврата шаблонной функции, несмотря на то, что тип возврата является void в любом случае, изменяет то, как выводится параметр типа этого шаблона. Правильны ли они? Также работает с C ++ 14, если вы реализуете is_invocable .
#include
template
// same thing happens with requires or is_invocable_v
std::enable_if_t Call(const F &f)
{
f(42);
}
// you can also use a lambda instead
struct Functor
{
template
auto operator()(T &&t) const
#if 0 // changing this to 1 makes it compile
-> void
#endif
{
static_assert(std::is_rvalue_reference_v);
}
};
int main()
{
Call(Functor());
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... -deduction