HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
utility
defer.hpp
1
// Copyright Take Vos 2022.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5
6
#include <type_traits>
7
#include <concepts>
8
#include <functional>
9
10
#pragma once
11
12
namespace
hi::inline
v1
{
13
20
class
defer
{
21
public
:
22
defer
() =
delete
;
23
defer
(
defer
&&) =
delete
;
24
defer
(
defer
const
&) =
delete
;
25
defer
&operator=(
defer
&&) =
delete
;
26
defer
&operator=(
defer
const
&) =
delete
;
27
28
template
<std::invocable<> Func>
29
[[nodiscard]]
defer
(Func &&func) noexcept : _func(std::forward<Func>(func)) {}
30
31
~defer
()
32
{
33
if
(_func) {
34
_func();
35
}
36
}
37
38
void
cancel()
noexcept
39
{
40
_func =
nullptr
;
41
}
42
43
private
:
44
std::function
<void()> _func;
45
};
46
47
}
48
v1
DOXYGEN BUG.
Definition
algorithm.hpp:13
v1::defer
Defer execution of a lambda to the end of the scope.
Definition
defer.hpp:20
std::function
Generated on Mon Apr 22 2024 12:52:15 for HikoGUI by
1.10.0