OGLplus
(0.59.0)
a C++ wrapper for rendering APIs
eagine
cleanup_group.hpp
Go to the documentation of this file.
1
9
#ifndef EAGINE_CLEANUP_GROUP_HPP
10
#define EAGINE_CLEANUP_GROUP_HPP
11
12
#include <
eagine/memory/object_storage.hpp
>
13
#include <
eagine/scope_exit.hpp
>
14
15
namespace
eagine
{
16
//------------------------------------------------------------------------------
17
class
cleanup_group {
18
private
:
19
memory::object_storage _storage;
20
21
public
:
22
template
<
23
typename
Func,
24
typename
= std::enable_if_t<std::is_invocable_v<Func>>,
25
typename
= std::enable_if_t<std::is_void_v<std::invoke_result_t<Func>>>>
26
auto
add(Func func) ->
auto
& {
27
return
_storage.template emplace<func_on_scope_exit<Func>>(
28
std::move(func));
29
}
30
31
template
<
32
typename
Func,
33
typename
= std::enable_if_t<std::is_invocable_v<Func>>>
34
auto
add_ret(Func func) ->
auto
& {
35
return
add([func{std::move(func)}]() { func(); });
36
}
37
38
void
reserve(
span_size_t
n) {
39
_storage.reserve(n);
40
}
41
42
auto
is_empty() const noexcept {
43
return
_storage.is_empty();
44
}
45
46
void
clear() noexcept {
47
_storage.clear();
48
}
49
};
50
//------------------------------------------------------------------------------
51
}
// namespace eagine
52
53
#endif // EAGINE_CLEANUP_GROUP_HPP
eagine::span_size_t
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition:
types.hpp:36
scope_exit.hpp
object_storage.hpp
eagine
Common code is placed in this namespace.
Definition:
eagine.hpp:21
Copyright © 2015-2021
Matúš Chochlík
.
<
chochlik -at -gmail.com
>
Documentation generated on Tue Apr 13 2021 by
Doxygen
(version 1.8.17).