diff --git a/include/pocketpy/obj.h b/include/pocketpy/obj.h index 597f23df..54383c68 100644 --- a/include/pocketpy/obj.h +++ b/include/pocketpy/obj.h @@ -111,6 +111,11 @@ struct PyObject final{ bool is_attr_valid() const noexcept { return _attr != nullptr; } void* _value_ptr() noexcept { return (char*)this + FIXED_SIZE; } + template T& as() noexcept { + static_assert(std::is_same_v>); + return *reinterpret_cast(_value_ptr()); + } + NameDict& attr() { PK_DEBUG_ASSERT(is_attr_valid()) return *_attr;