HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
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 "utility/module.hpp"
7
#include <type_traits>
8
#include <concepts>
9
#include <functional>
10
11
#pragma once
12
13
namespace
hi::inline
v1
{
14
21
class
defer
{
22
public
:
23
defer
() =
delete
;
24
defer
(
defer
&&) =
delete
;
25
defer
(
defer
const
&) =
delete
;
26
defer
&operator=(
defer
&&) =
delete
;
27
defer
&operator=(
defer
const
&) =
delete
;
28
29
template
<std::invocable<> Func>
30
[[nodiscard]]
defer
(Func &&func) noexcept : _func(std::forward<Func>(func)) {}
31
32
~defer
()
33
{
34
if
(_func) {
35
_func();
36
}
37
}
38
39
void
cancel()
noexcept
40
{
41
_func =
nullptr
;
42
}
43
44
private
:
45
std::function
<void()> _func;
46
};
47
48
}
49
v1
DOXYGEN BUG.
Definition
algorithm.hpp:13
v1::defer
Defer execution of a lambda to the end of the scope.
Definition
defer.hpp:21
std::function
Generated on Mon Apr 22 2024 12:52:19 for HikoGUI by
1.10.0