libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
deleter.hpp
Go to the documentation of this file.
1
#
ifndef
LIBJMMCG_CORE_DELETER_HPP
2
#
define
LIBJMMCG_CORE_DELETER_HPP
3
4
/******************************************************************************
5
** Copyright © 2004 by J.M.McGuiness, coder@hussar.me.uk
6
**
7
** This library is free software; you can redistribute it and/or
8
** modify it under the terms of the GNU Lesser General Public
9
** License as published by the Free Software Foundation; either
10
** version 2.1 of the License, or (at your option) any later version.
11
**
12
** This library is distributed in the hope that it will be useful,
13
** but WITHOUT ANY WARRANTY; without even the implied warranty of
14
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
** Lesser General Public License for more details.
16
**
17
** You should have received a copy of the GNU Lesser General Public
18
** License along with this library; if not, write to the Free Software
19
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
*/
21
22
#
include
"blatant_old_msvc_compiler_hacks.hpp"
23
24
#
include
<
functional
>
25
26
#
include
<
stdlib
.
h
>
27
28
namespace
jmmcg
{
namespace
LIBJMMCG_VER_NAMESPACE
{
29
30
/// A trivial class to use global free() to deallocate the memory using an RAII-style wrapper.
31
template
<
class
T>
32
struct
free_ptr
{
33
typedef
T
element_type
;
34
35
const
element_type
ptr
;
36
37
constexpr
free_ptr
()
noexcept
(
true
)
38
:
ptr
() {
39
}
40
explicit
constexpr
free_ptr
(
element_type
p)
noexcept
(
true
)
41
:
ptr
(p) {
42
}
43
free_ptr
(
free_ptr
const
&)=
delete
;
44
~
free_ptr
()
noexcept
(
true
) {
45
::free(
ptr
);
46
}
47
};
48
49
/**
50
Unfortunately std::default_delete does not name the type passed to it. This class fixes that.
51
52
\see std:default_delete
53
*/
54
template
<
class
V>
55
struct
default_delete
:
std
::default_delete<V> {
56
typedef
V
element_type
;
57
};
58
59
/// Another trivial class to make calling the dtor of an object into a functor.
60
template
<
class
V>
61
struct
placement_dtor
{
62
typedef
V
element_type
;
63
64
void
FORCE_INLINE
operator
()(
element_type
*v)
const
noexcept
(
true
) {
65
v->~V();
66
}
67
};
68
69
/// Another trivial class to make calling the dtor of an object into a functor, but actually does nothing.
70
template
<
class
V>
71
struct
noop_dtor
{
72
typedef
V
element_type
;
73
74
constexpr
void
operator
()(
element_type
*)
const
noexcept
(
true
) {
75
}
76
};
77
78
} }
79
80
#
endif
core
deleter.hpp
Generated on Tue May 11 2021 17:16:04 for libjmmcg by
1.9.2