HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
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.hpp"
7#include <type_traits>
8#include <concepts>
9
10#pragma once
11
12namespace hi::inline v1 {
13
20template<std::invocable<> T>
21class defer {
22public:
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]] constexpr defer(Func &&func) noexcept : _func(std::forward<Func>(func)) {}
31
32 constexpr ~defer()
33 {
34 std::move(_func)();
35 }
36
37private:
38 T _func;
39};
40
41template<std::invocable<> Func>
43
44}
45
Utilities used by the HikoGUI library itself.
DOXYGEN BUG.
Definition algorithm.hpp:15
Defer execution of a lambda to the end of the scope.
Definition defer.hpp:21
T move(T... args)