Skip to content

Commit

Permalink
scope_exit: release on move, and forward func in primary constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
capitalistspz committed Sep 16, 2024
1 parent 7d83a1b commit 11d68c7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Common/precompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ namespace stdx
bool m_released = false;
public:
explicit scope_exit(Fn&& f) noexcept
: m_func(std::move(f))
: m_func(std::forward<Fn>(f))
{}
~scope_exit()
{
if (!m_released) m_func();
}
scope_exit(scope_exit&& other) noexcept
: m_func(std::move(other.m_func)), m_released(std::exchange(other.m_released, false))
: m_func(std::move(other.m_func)), m_released(std::exchange(other.m_released, true))
{}
scope_exit(const scope_exit&) = delete;
scope_exit& operator=(scope_exit) = delete;
Expand Down

0 comments on commit 11d68c7

Please sign in to comment.