From 0da5644db566aab74da1152cb50d1604bf0a9627 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 25 May 2024 15:06:40 +0800 Subject: [PATCH] Update obj.h --- include/pocketpy/obj.h | 5 +++++ 1 file changed, 5 insertions(+) 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;