Skip to content

Commit 7402c91

Browse files
Improve Arduino compatibility with the STL
Replaced the min and max macros with std::min and std::max to allow compilation of bits/stl_algobase.h, a core component of many STL components such as std::function.
1 parent 5564125 commit 7402c91

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cores/arduino/Arduino.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void loop( void ) ;
7777
#include "WMath.h"
7878
#include "HardwareSerial.h"
7979
#include "pulse.h"
80+
#include <bits/stl_algobase.h>
8081
#endif
8182
#include "delay.h"
8283
#ifdef __cplusplus
@@ -92,6 +93,7 @@ void loop( void ) ;
9293
#include "wiring_shift.h"
9394
#include "WInterrupts.h"
9495

96+
#ifndef __cplusplus
9597
// undefine stdlib's abs if encountered
9698
#ifdef abs
9799
#undef abs
@@ -100,8 +102,14 @@ void loop( void ) ;
100102
#define min(a,b) ((a)<(b)?(a):(b))
101103
#define max(a,b) ((a)>(b)?(a):(b))
102104
#define abs(x) ((x)>0?(x):-(x))
103-
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
104105
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
106+
#else
107+
using std::min;
108+
using std::max;
109+
110+
#endif
111+
112+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
105113
#define radians(deg) ((deg)*DEG_TO_RAD)
106114
#define degrees(rad) ((rad)*RAD_TO_DEG)
107115
#define sq(x) ((x)*(x))

0 commit comments

Comments
 (0)