Skip to content

Commit

Permalink
Fixed scope exit class.
Browse files Browse the repository at this point in the history
  • Loading branch information
5cript committed Nov 30, 2024
1 parent 7ac7d97 commit 8dbfc2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
28 changes: 8 additions & 20 deletions nui/include/nui/utility/scope_exit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,25 @@

#include <functional>
#include <utility>
#include <concepts>

namespace Nui
{
template <typename EF>
class ScopeExit
{
public:
ScopeExit(EF&& func)
: onExit_(std::forward<EF>(func))
template <typename FunctionT>
requires std::invocable<FunctionT>
explicit ScopeExit(FunctionT&& func)
: onExit_(std::forward<FunctionT>(func))
{}
~ScopeExit()
{
if (onExit_)
onExit_();
}
ScopeExit(ScopeExit&& other)
: onExit_(std::move(other.onExit_))
{
other.onExit_ = {};
}
ScopeExit& operator=(ScopeExit&& other)
{
if (this != &other)
{
onExit_ = std::move(other.onExit_);
other.onExit_ = {};
}
return *this;
}
ScopeExit(ScopeExit&& other) = delete;
ScopeExit& operator=(ScopeExit&& other) = delete;
ScopeExit(const ScopeExit&) = delete;
ScopeExit& operator=(const ScopeExit&) = delete;
void disarm()
Expand All @@ -43,8 +33,6 @@ namespace Nui
private:
std::function<void()> onExit_;
};
template <typename T>
ScopeExit(T) -> ScopeExit<T>;

namespace Detail
{
Expand All @@ -53,7 +41,7 @@ namespace Nui
template <typename FunctionT>
auto operator->*(FunctionT&& fn) const
{
return ScopeExit<FunctionT>(std::forward<FunctionT>(fn));
return ScopeExit{std::forward<FunctionT>(fn)};
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace Nui::MacOs

id wkWebViewConfigurationFromOptions(HostNameMappingInfo const* mappingInfo, WindowOptions const& options)
{
std::vector<Nui::ScopeExit<std::function<void()>>> cleaners;
std::vector<Nui::ScopeExit> cleaners;

auto const* opts = &options;
std::optional<WindowOptions> optCopy;
Expand Down

0 comments on commit 8dbfc2c

Please sign in to comment.