Код: Выделить всё
enum class SomeEnum {
ONE = 1,
TWO = 2,
};
template
struct Signature {
static constexpr SomeEnum Type = _Type;
using Result = _Result;
using Args = std::tuple;
std::function func;
};
template <
SomeEnum _Type,
typename _Result,
typename... _Args>
Signature make(
std::function func) {
return Signature{.func = func};
}
template
Signature make(
_Result (*func)(_Args...)) {
return Signature{
.func = std::move(func)};
}
void foo(int x, std::string y, int z) {
}
auto sig1 = make(&foo);
auto sig2 = make([](int x, std::string y, int z) {
});
Код: Выделить всё
auto sig1 = make(&foo);
Код: Выделить всё
auto sig2 = make([](int x, std::string y, int z) {
});
Код: Выделить всё
main.cpp:40:13: error: no matching function for call to 'make'
auto sig2 = make([](int x, std::string y, int z) {
^~~~~~~~~~~~~~~~~~~
main.cpp:23:37: note: candidate template ignored: could not match 'std::function' against '(lambda at main.cpp:40:33)'
Signature make(
^
main.cpp:29:37: note: candidate template ignored: could not match '_Result (*)(_Args...)' against '(lambda at main.cpp:40:33)'
Signature make(
^
1 error generated.
Код: Выделить всё
std::function l = [](int x, std::string y, int z) {
};
auto sig2 = make(l);
Код: Выделить всё
auto sig2 = make([](int x, std::string y, int z) {
});
Подробнее здесь: https://stackoverflow.com/questions/790 ... uced-types