summaryrefslogtreecommitdiff
path: root/UsedMacro.h
blob: 44fc75a0f895a8d41bef868d3ef1d1e6f54481a5 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#pragma once

//³£Óú궨Òå¿â
//20191111-1705

#include <cstdio>
#include <cassert>

#include <iostream>

#include <type_traits>
#include <utility>

#include <string>

#include <exception>
#include <stdexcept>


//**********
//±êʶ·û²Ù×÷
//**********

#define SYMBOL_STR(id) #id//ת±ä×Ö·û´®



#define CONNECT_SYMBOL_2(str1, str2) str1##str2
#define CONNECT_SYMBOL_3(str1, str2, str3) str1##str2##str3
#define CONNECT_SYMBOL_4(str1, str2, str3, str4) str1##str2##str3##str4



//************
//ÊýÖµÔËËã²Ù×÷
//************

#define NEG_TO(x) ((x) = -(x))//¸³Ïà·´Êý
#define NOT_TO(x) ((x) = !(x))//¸³²¼¶û·Ç
#define INV_TO(x) ((x) = ~(x))//¸³°´Î»È¡·´


#define ABS_OF(x) ((x)>0? (x):-(x))//È¡¾ø¶ÔÖµ
#define ABS_TO(x) ((x) = ABS_OF(x))//¸³¾ø¶ÔÖµ


#define DIS_OF(x, y) (ABS_OF((x)-(y)))//È¡²îÖµ



#define MAX_OF(x, y) ((x)>(y)? (x):(y))//È¡×î´óÖµ
#define MIN_OF(x, y) ((x)<(y)? (x):(y))//È¡×îСֵ


#define MAX_TO(x, lim) ((x) = MAX_OF(x, lim))//¸³×î´óÖµ
#define MIN_TO(x, lim) ((x) = MIN_OF(x, lim))//¸³×îСֵ

#define HIGH_LIMIT(x, lim) MIN_TO(x, lim)//ÉèÖÃÉÏÏÞ
#define LOW_LIMIT(x, lim) MAX_TO(x, lim)//ÉèÖÃÏÂÏÞ


#define RANGE_OF(x, llim, hlim) ((x)<(llim)? (llim): (x)>(hlim)? (hlim):(x))//È¡·¶Î§
#define RANGE_LIMIT(x, llim, hlim) ((x) = RANGE_OF(x, llim, hlim))//ÉèÖ÷¶Î§


#define IS_IN_RANGE(x, llim, hlim) ((x)>=(llim) && (x)<=(hlim))//ÅжÏÊÇ·ñÔÚ·¶Î§ÄÚ
#define IS_IN_ITER_RANGE(x, st, ed) ((x)>=(st) && (x)<(ed))//ÅжÏÊÇ·ñÔÚ·¶Î§ÄÚ£¬ÒÔµü´úÆ÷±ê×¼



#define SQUARE_OF(x) ((x)*(x))//Ç󯽷½
#define SQUARE_TO(x) ((x) = SQUARE_OF(x))//¸³ÖµÆ½·½



//************
//ÔËËãÊ¡ÂÔ²Ù×÷
//************



#define LIST_GO(p, m_p) ((p) = (p)->m_p)//Á´±íÖ¸ÕëÒÆ¶¯

#define LIST_CNNT(p1, m_p1, p2, m_p2) \
	(((p1)->m_p1=p2), ((p2)->m_p2=p1))//Ë«ÏòÁ´±íÁ¬½Ó

#define LIST_ADD(p1, m_p1, p2, m_p2, pNew) \
	(LIST_CNNT(p1, m_p1, pNew, m_p2), LIST_CNNT(pNew, m_p1, p2, m_p2))//Ë«ÏòÁ´±íÌí¼Ó



#define ARR_SIZE(arr) (sizeof(decltype(arr))\
	/sizeof(typename std::remove_extent<decltype(arr)>::type))//ÇóÊý×é´óС

#define ARR_SIZE_ALL(arr) (sizeof(decltype(arr))\
	/sizeof(typename std::remove_all_extents<decltype(arr)>::type))//Çó¸ùÊý×é´óС



#define SHOW_BEGIN_END(container) std::begin(container), std::end(container)//ÁгöÈÝÆ÷µÄbeginºÍendº¯Êý



#define O_(id) CONNECT_SYMBOL_2(o_, id)//Ìí¼Óԭʼǰ׺

#define O_INIT(id) id(O_(id))//ʹÓÃǰ׺°æ±¾³õʼ»¯
#define O_INIT_MOVE(id) id(std::move(O_(id)))//ʹÓÃǰ׺°æ±¾Òƶ¯³õʼ»¯
#define O_INIT_FORWARD(id, Ty) id(std::forward<Ty>(O_(id)))//ʹÓÃǰ׺°æ±¾×ª·¢³õʼ»¯

#define O_ASSIGN(id) (id = O_(id))//ʹÓÃǰ׺°æ±¾¸³Öµ
#define O_ASSING_MOVE(id) (id = std::move(O_(id)))//ʹÓÃǰ׺°æ±¾Òƶ¯¸³Öµ
#define O_ASSIGN_FORWARD(id, Ty) (id = std::forward<Ty>(O_(id)))//ʹÓÃǰ׺°æ±¾×ª·¢³õʼ»¯


#define OTHER_INIT(other, mem) mem((other).mem)//ʹÓÃÀà³ÉÔ±³õʼ»¯
#define OTHER_INIT_MOVE(other, mem) mem(std::move(other).mem)//ʹÓÃÀà³ÉÔ±ÒÆ¶¯³õʼ»¯
#define OTHER_INIT_FORWARD(other, mem, Ty) mem(std::forward<Ty>(other).mem)//ʹÓÃÀà³ÉԱת·¢³õʼ»¯

#define OTHER_ASSIGN(other, mem) (mem = (other).mem)//ʹÓÃÀà³ÉÔ±¸³Öµ
#define OTHER_ASSIGN_MOVE(other, mem) (mem = std::move(other).mem)//ʹÓÃÀà³ÉÔ±ÒÆ¶¯¸³Öµ
#define OTHER_ASSIGN_FORWARD(other, mem) (mem = std::forward<Ty>(other).mem)//ʹÓÃÀà³ÉԱת·¢¸³Öµ



//******
//¶àÓï¾ä²Ù×÷
//******

#define CLASS_ASSIGN(Type, other) {\
	if(this!=&(other)) {\
		this->~Type();\
		new(this) Type(other);\
	}}//¿½±´¸³Öµ£¬×¢Òâ»á¸²¸ÇÐé±í£¬²»½¨ÒéʹÓÃ

#define CLASS_ASSIGN_MOVE(Type, other) {\
	if(this!=&(other)) {\
		this->~Type();\
		new(this) Type(std::move(other));\
	}}//ÒÆ¶¯¸³Öµ£¬×¢Òâ»á¸²¸ÇÐé±í£¬²»½¨ÒéʹÓÃ


#define TEMPLATE_ASSIGN(Type, Typename, arg) {\
	this->~Type();\
	new(this) Type(std::forward<Typename>(arg));\
	}//Ä£°å¸³Öµ£¬×Ô¸³Öµ²»°²È«£¬×¢Òâ»á¸²¸ÇÐé±í£¬²»½¨ÒéʹÓÃ

#define TEMPLATE_PACKET_ASSIGN(Type, Typenames, args) {\
	this->~Type();\
	new(this) Type(std::forward<Typenames>(args)...);\
	}//Ä£°å°ü¸³Öµ£¬×Ô¸³Öµ²»°²È«£¬×¢Òâ»á¸²¸ÇÐé±í£¬²»½¨ÒéʹÓÃ



//******
//ÉùÃ÷²Ù×÷
//******

#define DEFINE_INLINE_VERIABLE(Type, name) \
inline Type &name() \
{\
	static Type value;\
	return value;\
}//¶¨ÒåÄÚÁª±äÁ¿

#define GET_INLINE_VARIABLE(name) name()//»ñÈ¡ÄÚÁª±äÁ¿