diff --git a/furvm/include/furvm/thing.hpp b/furvm/include/furvm/thing.hpp index 1531fdb..e5db73b 100644 --- a/furvm/include/furvm/thing.hpp +++ b/furvm/include/furvm/thing.hpp @@ -427,6 +427,12 @@ public: if (!detail::thing_traits{}(*m_type)) throw bad_thing_access(); return *std::launder(reinterpret_cast(m_data)); } + + template + void set(T&& newValue) { + if (!detail::thing_traits{}(*m_type)) throw bad_thing_access(); + *std::launder(reinterpret_cast(m_data)) = std::forward(newValue); + } public: /** * @brief Returns a sum of two things. diff --git a/furvm/test/test.cpp b/furvm/test/test.cpp index f560151..62e99f2 100644 --- a/furvm/test/test.cpp +++ b/furvm/test/test.cpp @@ -84,6 +84,9 @@ TEST(ThingOps, Access) { EXPECT_THROW(thing.get(), furvm::bad_thing_access); EXPECT_THROW(thing.get(), furvm::bad_thing_access); EXPECT_THROW(thing.get(), furvm::bad_thing_access); + + EXPECT_NO_THROW(thing.set(67)); // He talkin' 'bout sum 6-7 while I want sixty ni- + EXPECT_THROW(thing.set(1337), furvm::bad_thing_access); } } // namespace