From b3f3f0538e7eeb6baf0fadac0e5ef0447df1a547 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 6 Jul 2021 16:33:21 +0200 Subject: [PATCH] Shim on AVR Instead of adding #ifdefs for missing headers, create a shim that can be included everywhere. "limits.h" includes a bare-bone implementation of numeric_limits (to be extended as needed). --- src/hal/circular_buffer.h | 8 +------- src/limits.h | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 src/limits.h diff --git a/src/hal/circular_buffer.h b/src/hal/circular_buffer.h index 7e8249a..4330e15 100644 --- a/src/hal/circular_buffer.h +++ b/src/hal/circular_buffer.h @@ -1,10 +1,6 @@ #pragma once - -#include #include -#ifndef __AVR__ -#include -#endif +#include "../limits.h" /// A generic circular index class which can be used to build circular buffers /// Can hold up to size elements @@ -15,10 +11,8 @@ template class CircularIndex { public: -#ifndef __AVR__ static_assert(size <= std::numeric_limits::max() / 2, "index_t is too small for the requested size"); -#endif constexpr inline CircularIndex() : tail(0) diff --git a/src/limits.h b/src/limits.h new file mode 100644 index 0000000..232f03b --- /dev/null +++ b/src/limits.h @@ -0,0 +1,23 @@ +#pragma once +#ifndef __AVR__ +#include +#else + +// A minimal std::numeric_limits for platforms that lack one +#include +#include + +namespace std { + +template +class numeric_limits; + +template <> +class numeric_limits { +public: + static constexpr size_t max() { return UINT8_MAX; } +}; + +} // namespace std + +#endif