feat(furvm): allow setting thing's value
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user