#pragma once #include enum class ReportFlags { enabled, valid }; enum class StateEvent { active, inactive, activated, deactivated }; template concept boolean = std::is_same_v; template class State { public: explicit State(Object& object) : object(object) {} template StateEvent set(boolean auto... values) { static_assert(sizeof...(Indexes) == sizeof...(values)); const bool previous = flags.all(); (flags.set(indexOf<0, Indexes, Keys...>(), values), ...); if (previous != flags.all()) { if (flags.all()) { object.activate(); return StateEvent::activated; } else { object.deactivate(); return StateEvent::deactivated; } } return flags.all() ? StateEvent::active : StateEvent::inactive; } template bool get() const { return flags.test(indexOf<0, Index, Keys...>()); } bool isActive() const { return flags.all(); } private: template static constexpr size_t indexOf() { if constexpr (flag == it) { return Index; } else { return indexOf(); } } Object& object; std::bitset flags{0}; };