#pragma once #include namespace mln { class TaggedScheduler; template class OptionalActorRef { public: OptionalActorRef() = default; OptionalActorRef(bool syncRef, Object& object, std::weak_ptr weakMailbox) { if (syncRef) { objectRef = &object; } else { actorRef = std::make_optional>(object, weakMailbox); } } explicit OptionalActorRef(Object& object) { objectRef = &object; } explicit OptionalActorRef(ActorRef actorRef_) { actorRef = actorRef_; } template void invoke(Fn fn, Args&&... args) const { if (objectRef) { (objectRef->*fn)(std::forward(args)...); } else if (actorRef) { actorRef->invoke(fn, std::forward(args)...); } } private: Object* objectRef = nullptr; std::optional> actorRef; }; } // namespace mln