Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30e4397

Browse files
committed
Avoid max() and min() clash with c++ stdlib
1 parent7c9e4f8 commit30e4397

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

‎api/Common.h

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ typedef enum {
3737
#defineSERIAL0x0
3838
#defineDISPLAY0x1
3939

40-
#ifndefmin
41-
#definemin(a,b) \
42-
({ __typeof__ (a) _a = (a); \
43-
__typeof__ (b) _b = (b); \
44-
_a < _b ? _a : _b; })
45-
#endif
46-
47-
#ifndefmax
48-
#definemax(a,b) \
49-
({ __typeof__ (a) _a = (a); \
50-
__typeof__ (b) _b = (b); \
51-
_a > _b ? _a : _b; })
52-
#endif
53-
5440
#ifndef constrain
5541
#defineconstrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
5642
#endif
@@ -130,6 +116,33 @@ void loop(void);
130116
}// extern "C"
131117
#endif
132118

119+
#ifdef __cplusplus
120+
template<classT,classL>
121+
automin(const T& a,const L& b) -> decltype((b < a) ? b : a)
122+
{
123+
return (b < a) ? b : a;
124+
}
125+
126+
template<classT,classL>
127+
automax(const T& a,const L& b) -> decltype((b < a) ? b : a)
128+
{
129+
return (a < b) ? b : a;
130+
}
131+
#else
132+
#ifndef min
133+
#definemin(a,b) \
134+
({__typeof__ (a) _a = (a); \
135+
__typeof__ (b) _b = (b); \
136+
_a < _b ? _a : _b; })
137+
#endif
138+
#ifndef max
139+
#definemax(a,b) \
140+
({__typeof__ (a) _a = (a); \
141+
__typeof__ (b) _b = (b); \
142+
_a > _b ? _a : _b; })
143+
#endif
144+
#endif
145+
133146
#ifdef __cplusplus
134147

135148
/* C++ prototypes*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp