feat(furvm): allow setting thing's value

This commit is contained in:
2026-09-04 21:28:28 +02:00
parent 24a9530abc
commit 6c7d16631d
2 changed files with 9 additions and 0 deletions
+6
View File
@@ -427,6 +427,12 @@ public:
if (!detail::thing_traits<T>{}(*m_type)) throw bad_thing_access(); if (!detail::thing_traits<T>{}(*m_type)) throw bad_thing_access();
return *std::launder(reinterpret_cast<const T*>(m_data)); return *std::launder(reinterpret_cast<const T*>(m_data));
} }
template <typename T>
void set(T&& newValue) {
if (!detail::thing_traits<T>{}(*m_type)) throw bad_thing_access();
*std::launder(reinterpret_cast<T*>(m_data)) = std::forward<T>(newValue);
}
public: public:
/** /**
* @brief Returns a sum of two things. * @brief Returns a sum of two things.
+3
View File
@@ -84,6 +84,9 @@ TEST(ThingOps, Access) {
EXPECT_THROW(thing.get<furvm::s8>(), furvm::bad_thing_access); EXPECT_THROW(thing.get<furvm::s8>(), furvm::bad_thing_access);
EXPECT_THROW(thing.get<furvm::s32>(), furvm::bad_thing_access); EXPECT_THROW(thing.get<furvm::s32>(), furvm::bad_thing_access);
EXPECT_THROW(thing.get<void*>(), furvm::bad_thing_access); EXPECT_THROW(thing.get<void*>(), furvm::bad_thing_access);
EXPECT_NO_THROW(thing.set<furvm::u8>(67)); // He talkin' 'bout sum 6-7 while I want sixty ni-
EXPECT_THROW(thing.set<furvm::s32>(1337), furvm::bad_thing_access);
} }
} // namespace } // namespace