How do I #include <limits> in my Arduino Nano sketch?

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;
  };

Maybe

#include <limits.h>

#include <limits.h> is already there. Maybe I need to add more to my sample

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'.

Which Arduino board? The core for AVR-based boards doesn't support STL.

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.

Your original question has been answered, the Nano is an AVR-based board.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.