使用以下代码如何正确编写自定义模板推导?
template<class R, class State, class... Ts> struct visitor : Ts... { using Ts::operator()...; };
template<class R, class State, class... Ts> visitor(State, Ts...)->visitor<class R, State,Ts...>;
using Event = std::variant<HeartBeat, ConfigurationRead>;
using State = std::variant<Idle, Starting, Running, Error>;
void case3()
{
Event e;
State currentState;
State newState = std::visit( visitor{
[](Idle&& state, HeartBeat event) {std::cout << "Currently stopped, heartbeat received.\n"; return Error{}; }
}, currentState, e);
}
我查看了几个示例,但找不到使用 std::visit 返回的示例。