#pragma once #include #include namespace vl::mixin { template struct CallbackInfoReturnable; // Base callback info: allows cancellation of original behavior. struct CallbackInfo { void cancel() noexcept { cancelled_ = true; } bool isCancelled() const noexcept { return cancelled_; } private: bool cancelled_ = false; template friend class CallbackInfoReturnable; }; // Returnable variant: holds an optional return value. template struct CallbackInfoReturnable : CallbackInfo { template void setReturnValue(T&& v) { value_ = static_cast(std::forward(v)); this->cancel(); // setting a value implies skipping original unless user calls uncancel() } bool hasReturnValue() const noexcept { return value_.has_value(); } const Ret& getReturnValue() const { return *value_; } Ret& getReturnValue() { return *value_; } void clearReturnValue() { value_.reset(); } void uncancel() { if (!value_) /*no explicit value*/ cancelled_ = false; } private: using CallbackInfo::cancelled_; std::optional value_; }; } // namespace vl::mixin