#pragma once #include union SDL_Event; enum ModeSecondClick { Unset, Reset, NoAction }; template class Mode { public: explicit Mode(Target & t) : target {t} { } Target & target; template auto toggle(Params &&... params) { return [params..., this](const SDL_Event &) { toggleSetMode(std::forward(params)...); }; } private: template void toggleSetMode(Params &&... params) { if (dynamic_cast(target.get())) { if constexpr (msc == ModeSecondClick::Unset) { target.reset(); } if constexpr (msc == ModeSecondClick::Reset) { target = std::make_unique(std::forward(params)...); } } else { target = std::make_unique(std::forward(params)...); } } };