Bugfix in util::function: forward the callable instead of moving it

This commit is contained in:
Nikita Lisitsa 2021-03-04 14:31:15 +03:00
parent 4641c5d7d2
commit c26cf898ca

View file

@ -175,7 +175,7 @@ namespace psemek::util
if constexpr (uses_static_storage<T>::value)
{
new (reinterpret_cast<T *>(&storage_)) T(std::move(f));
new (reinterpret_cast<T *>(&storage_)) T(std::forward<F>(f));
static vtable m = {
[](void * src, void * dst){ new (reinterpret_cast<T*>(dst)) T(std::move(*reinterpret_cast<T*>(src))); },
@ -187,7 +187,7 @@ namespace psemek::util
}
else
{
*reinterpret_cast<T**>(&storage_) = new T(std::move(f));
*reinterpret_cast<T**>(&storage_) = new T(std::forward<F>(f));
static vtable m = {
[](void * src, void * dst){ *reinterpret_cast<T**>(dst) = *reinterpret_cast<T**>(src); *reinterpret_cast<T**>(src) = nullptr; },