I want to create a template alias for the std::function
template <typename T, typename R>
using Func = std::function<R(T)>;
Next, initialize two variables using this alias:
Func<int, void> f = [](int x) { }; // ok
Func<void, int> g = []() { return 1; }; // error
Unfortunately, the second line rises the following error:
In substitution of
‘template<class T, class R>
using Func = std::function<R(T)> [with T = void; R = int]’:
error: invalid parameter type ‘void’
From my point of view, the line causing the error must be equivalent to
std::function<int(void)> h = [](){ return 1; };
which, of course, compiles fine.
Can somebody explain what's going on here, please?
Edit
Unfortunately, I haven't found a clear answer in related questions, including this one. After reading these answers, it is still unclear for me what is the origin of the problem with the code above. I am looking for a simple concise answer, perfectly, backed up by the references to the language specification.