#pragma once #include #include #include "Private.h" namespace crepe { template T & Private::set(Args &&... args) { if (!this->empty()) this->destructor(this->instance); T * instance = new T(std::forward(args)...); this->instance = static_cast(instance); this->destructor = [](void * instance) { delete static_cast(instance); }; this->type = typeid(T); return *instance; } template T & Private::get() { using namespace std; if (this->empty()) throw out_of_range("Private: get() called on empty object"); type_index requested_type = typeid(T); if (this->type != requested_type) throw logic_error(format("Private: get() called with [T = {}] (actual is [T = {}])", requested_type.name(), this->type.name())); return *static_cast(this->instance); } } // namespace crepe