I am trying to use std::numeric_limits<T>::max() etc in a templated class, but my #include <limits> generates fatal error: limits: No such file or directory.
My source (with some #if statements) compiles with EpoxyDuino, but of course that is only for my Linux host.
How do I go about getting information about template types? like (I hope I trimmed this correctly)
#include <limits.h> // does not include std::numeric_limits stuff
template<typename T>
class SampleAccum {
public:
SampleAccum()
: m_Highest(std::numeric_limits<T>::min()) {}
T getHighest() const { return m_Highest; }
protected:
T m_Highest;
};
The problem seems to be that someone (perhaps who doesn't understand C++; maybe it's an ancient legacy thing) has decided that min and max should be #define-d macros.
My fix was to hack a copy of /usr/include/c++/9/limits (which I called numeric_limits in my Arduino utilities folder) to compile, with #undef min, #undef max, skip the #include <bits/c++config.h> then hack-and-fix the many compilation errors. It's fugly code, but IWFM. It's over 1700 LOC so maybe a bit big to insert here.
Maybe there needs to be a compile switch (#pragma?) for 'C code' or 'C++ code'.
It's an Arduino Nano (topic header changed to now include this). Maybe it's not supported by the AVR core, but with my hacked #include <numeric_limits>, I can now get template code like my sample working just fine, with unit tests showing std::numeric_limits<T>::min() etc behaving as expected.