Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type alias for std::function

I'm trying to alias the std::function type because I plan on using something else in the future. And I would like to be able to easily make that change. But I'm getting an error message from the compiler that I don't really understand. I understand what it means but I don't understand it in this context.

Example:

#include <functional>

template < typename Ret, typename... Args > using MyFunc = std::function< Ret(Args...) >;

int main(int argc, char **argv)
{
    MyFunc<void(int)> fn;

    return 0;
}

Generates:

..\main.cpp|7|required from here|
..\main.cpp|3|error: function returning a function|
like image 656
SLC Avatar asked Dec 15 '22 10:12

SLC


1 Answers

template <typename F>
using MyFunc = std::function<F>;

void(int) is a single (function) type.

like image 116
yuri kilochek Avatar answered Dec 27 '22 01:12

yuri kilochek