I want the addAction method to support 0 or more arguments for the lambda functions being passed in. I get the error shown below even if I remove <TrackSelect>from the method call. Caveat, I don't want to use std::function because this is meant for an embedded platform.
In file included from include/melseq.h:12,
from src/melseq.cpp:1:
include/menu.h:85:10: note: candidate: 'template<class ... Payload> void Menu::addAction(MenuActionId, void (&&)(GUI*, Payload ...), void (&&)(GUI*, Payload ...))'
85 | void addAction(MenuActionId id, Callback<Payload...> &&onActive, Callback<Payload...> &&onDefault)
| ^~~~~~~~~
include/menu.h:85:10: note: template argument deduction/substitution failed:
src/melseq.cpp:38:37: note: mismatched types 'Menu::Callback<Payload ...>' and 'Melseq::setup(Adafruit_SH1107*)::<lambda(GUI*, TrackSelect)>'
The calling code:
mainMenu_.addAction<TrackSelect>(
MenuActionId::TrackSelect,
[](GUI *gui, TrackSelect payload)
{
gui->drawCell(payload.cell, {1, 1}, 1);
gui->drawStringAtCell(payload.cell, {1, 1}, payload.name.data(), 1);
},
[](GUI *gui, TrackSelect payload)
{
gui->drawCell(payload.cell, {1, 1}, 0);
gui->drawStringAtCell(payload.cell, {1, 1}, payload.name.data(), 0);
}
);
The implementation code:
class Menu {
// ... stuff
template <typename... Payload>
using Callback = void(GUI *, Payload...);
template <typename... Payload>
void addAction(MenuActionId id, Callback<Payload...> &&onActive, Callback<Payload...> &&onDefault)
{
actions_.emplace_back(id, etl::move(onActive), etl::move(onDefault));
}
// stuff
}