From 7402c9156de64a574489f56bf515654989054782 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 10 Apr 2019 16:10:03 -0700 Subject: [PATCH 1/6] 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. --- cores/arduino/Arduino.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index e645743b2..bca57513a 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -77,6 +77,7 @@ void loop( void ) ; #include "WMath.h" #include "HardwareSerial.h" #include "pulse.h" + #include #endif #include "delay.h" #ifdef __cplusplus @@ -92,6 +93,7 @@ void loop( void ) ; #include "wiring_shift.h" #include "WInterrupts.h" +#ifndef __cplusplus // undefine stdlib's abs if encountered #ifdef abs #undef abs @@ -100,8 +102,14 @@ void loop( void ) ; #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abs(x) ((x)>0?(x):-(x)) -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#else + using std::min; + using std::max; + +#endif + +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG) #define sq(x) ((x)*(x)) From 5800fce9e8c4ee21e61bfe9bce9346c68095d58b Mon Sep 17 00:00:00 2001 From: per1234 Date: Thu, 11 Apr 2019 08:32:11 -0700 Subject: [PATCH 2/6] Apply suggestions from code review Fixed styling Co-Authored-By: db-dropDatabase --- cores/arduino/Arduino.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index bca57513a..abaa11205 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -104,9 +104,8 @@ void loop( void ) ; #define abs(x) ((x)>0?(x):-(x)) #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #else - using std::min; - using std::max; - + using std::min; + using std::max; #endif #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) From 3991f0acf34ff16e0df9b13d89ad11da3ae6e811 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 11 Apr 2019 09:01:37 -0700 Subject: [PATCH 3/6] Replaced `using` declarations with custom implementation Created multi-type template for min and max. --- cores/arduino/Arduino.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index abaa11205..4707f1e70 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -1,17 +1,14 @@ /* Arduino.h - Main include file for the Arduino SDK Copyright (c) 2014 Arduino LLC. All right reserved. - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -104,8 +101,17 @@ void loop( void ) ; #define abs(x) ((x)>0?(x):-(x)) #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #else - using std::min; - using std::max; + template + auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) + { + return (b < a) ? b : a; + } + + template + auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) + { + return (a < b) ? b : a; + } #endif #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) From 5460bde33fc5ab952859a71d2a89c94cb7ebeb87 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 11 Apr 2019 09:18:36 -0700 Subject: [PATCH 4/6] Fix License typos --- cores/arduino/Arduino.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 4707f1e70..6d88553a2 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -1,14 +1,17 @@ /* Arduino.h - Main include file for the Arduino SDK Copyright (c) 2014 Arduino LLC. All right reserved. + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA From ab462d934fb31575439f1d89cee6031e84995706 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 30 Jul 2019 09:40:29 -0700 Subject: [PATCH 5/6] Fixed typo in decltype specifier --- cores/arduino/Arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 6d88553a2..beb61d8b5 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -111,7 +111,7 @@ void loop( void ) ; } template - auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) + auto max(const T& a, const L& b) -> decltype((a < b) ? b : a) { return (a < b) ? b : a; } From c92a52d9a79e35799d172397b27a838f80cbb8aa Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 8 Aug 2019 17:14:06 -0700 Subject: [PATCH 6/6] Remove extra include --- cores/arduino/Arduino.h | 1 - 1 file changed, 1 deletion(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index beb61d8b5..8e4b97f3e 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -77,7 +77,6 @@ void loop( void ) ; #include "WMath.h" #include "HardwareSerial.h" #include "pulse.h" - #include #endif #include "delay.h" #ifdef __cplusplus