#pragma once #include #include "OptionalRef.h" namespace crepe { template OptionalRef::OptionalRef(T & ref) { this->set(ref); } template OptionalRef::OptionalRef(const OptionalRef & other) { this->ref = other.ref; } template OptionalRef::OptionalRef(OptionalRef && other) { this->ref = other.ref; other.clear(); } template OptionalRef & OptionalRef::operator=(const OptionalRef & other) { this->ref = other.ref; return *this; } template OptionalRef & OptionalRef::operator=(OptionalRef && other) { this->ref = other.ref; other.clear(); return *this; } template T & OptionalRef::get() const { if (this->ref == nullptr) throw std::runtime_error("OptionalRef: attempt to dereference nullptr"); return *this->ref; } template void OptionalRef::set(T & ref) noexcept { this->ref = &ref; } template void OptionalRef::clear() noexcept { this->ref = nullptr; } template OptionalRef & OptionalRef::operator=(T & ref) { this->set(ref); return *this; } template OptionalRef::operator bool() const noexcept { return this->ref != nullptr; } } // namespace crepe