Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of <algorithm> for min/max not compatible with many libraries #184

Closed
terrillmoore opened this issue Nov 2, 2021 · 0 comments
Closed
Assignees
Labels

Comments

@terrillmoore
Copy link
Member

The STM32 BSP uses the following code for min/max:

In cores\arduino\wiring_constants.h, lines 24 ff:

#ifdef __cplusplus
#include <algorithm>
using std::min;
using std::max;
#else // C
...

Unfortunately, with the version of the compiler and libraries that we use, this causes things like the Adafruit ePaper Display Library not to compile, with cryptic warnings related to iterators pointing at uses of min and max. Comparing to other BSPs, I found that the Arduino.cc H7 BSP provides its own implementation:

In cores\arduino\api\Common.h, lines 122 ff:

#ifdef __cplusplus
  template<class T, class L> 
  auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
  {
    return (b < a) ? b : a;
  }

  template<class T, class L> 
  auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
  {
    return (a < b) ? b : a;
  }
#else
...

This (and the Adafruit/MCCI SAMD BSP, which just #define min() and max()) compile the Adafruit libraries without difficulty.

Patching the STM32 BSP with the code from the H7 BSP solves the problem.

@terrillmoore terrillmoore self-assigned this Nov 2, 2021
terrillmoore added a commit that referenced this issue Nov 15, 2021
Fix #184: don't use <algorithm> for min/max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant