scoped: simplify universal references
this avoids problems with use after stack unwind discovered using sanitizers.
This commit is contained in:
parent
db90a4db53
commit
d74fca4e98
14
scoped.hpp
14
scoped.hpp
@ -16,6 +16,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace util::scoped {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -78,12 +80,8 @@ namespace util::scoped {
|
||||
template <typename FuncT, typename ...Args>
|
||||
class function {
|
||||
public:
|
||||
explicit function (FuncT &&_function, Args&& ..._args)
|
||||
noexcept (
|
||||
std::is_nothrow_move_constructible_v<FuncT> &&
|
||||
std::is_nothrow_move_constructible_v<std::tuple<Args...>>
|
||||
):
|
||||
m_function (std::move (_function)),
|
||||
explicit function (FuncT &&_function, Args&& ..._args):
|
||||
m_function (std::forward<FuncT> (_function)),
|
||||
m_args (std::forward<Args> (_args)...)
|
||||
{ ; }
|
||||
|
||||
@ -93,7 +91,7 @@ namespace util::scoped {
|
||||
~function ()
|
||||
{
|
||||
if (m_enabled)
|
||||
std::apply (std::move (m_function), std::move (m_args));
|
||||
std::apply (m_function, m_args);
|
||||
}
|
||||
|
||||
void disable (void) { m_enabled = false; }
|
||||
@ -107,5 +105,5 @@ namespace util::scoped {
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename FuncT, typename ...Args>
|
||||
function (FuncT &&, Args&&...) -> function<FuncT&&,Args&&...>;
|
||||
function (FuncT,Args...) -> function<FuncT,Args...>;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user