-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
43 lines (36 loc) · 955 Bytes
/
utils.h
File metadata and controls
43 lines (36 loc) · 955 Bytes
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
#pragma once
#if defined(NDEBUG)/* || defined(__OPTIMIZE__) */
# define MA_DEBUG 0
#else
# define MA_DEBUG 1
#endif
#if MA_DEBUG
#define dprintf(_format, ...) fprintf(stderr, _format, ##__VA_ARGS__)
#else
#define dprintf(_format, ...)
#endif
#pragma region defer
namespace ma{
template<typename T>
struct exit_scope
{
T lambda;
exit_scope(T lambda):lambda(lambda){}
~exit_scope(){lambda();}
exit_scope(const exit_scope&) = delete;
private:
exit_scope& operator =(const exit_scope&) = delete;
};
class exit_scope_help
{
public:
template<typename T>
exit_scope<T> operator +(T t){return t;}
};
} // namespace ma
/// Concatenate preprocessor tokens a and b after macro-expanding them.
#define MA_CONCAT__(a, b) a ## b
#define MA_CONCAT_(a, b) MA_CONCAT__(a, b)
#define MA_CONCAT(a, b) MA_CONCAT_(a, b)
#define defer const auto& MA_CONCAT(_defer__, __LINE__) = ::ma::exit_scope_help() + [&]()
#pragma endregion defer