forked from anqin/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclosure_helper.h
More file actions
63 lines (52 loc) · 1.23 KB
/
closure_helper.h
File metadata and controls
63 lines (52 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2014 The Trident Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
#ifndef _TRIDENT_CLOSURE_HELPER_H_
#define _TRIDENT_CLOSURE_HELPER_H_
namespace trident {
template <typename T>
inline T * get_pointer(T * p)
{
return p;
}
// delete p in dtor automatically if Enabled is true
template <bool Enabled, typename T>
class ConditionalAutoDeleter
{
public:
explicit ConditionalAutoDeleter(T* p)
: m_p(p)
{
}
~ConditionalAutoDeleter()
{
if (Enabled)
{
delete m_p;
}
}
private:
ConditionalAutoDeleter(const ConditionalAutoDeleter&);
ConditionalAutoDeleter& operator=(const ConditionalAutoDeleter&);
private:
T* m_p;
};
// This is a typetraits object that's used to take an argument type, and
// extract a suitable type for storing and forwarding arguments.
template <typename T>
struct ParamTraits
{
typedef const T& ForwardType;
typedef T StorageType;
};
template <typename T>
struct ParamTraits<T&>
{
typedef T& ForwardType;
typedef T StorageType;
};
} // namespace trident
#endif // _TRIDENT_CLOSURE_HELPER_H_
/* vim: set ts=4 sw=4 sts=4 tw=100 */