diff options
Diffstat (limited to 'playground')
-rw-r--r-- | playground/include/playground.h | 29 | ||||
-rw-r--r-- | playground/include/stm32f10x_conf.h | 6 |
2 files changed, 32 insertions, 3 deletions
diff --git a/playground/include/playground.h b/playground/include/playground.h index 168c5c5..3e1b4bc 100644 --- a/playground/include/playground.h +++ b/playground/include/playground.h @@ -13,11 +13,34 @@ int main(); extern "C" void Default_Handler(); +#include <cstdint> +#include <limits> +#include <utility> + // TODO: replace with std::extent<>; http://en.cppreference.com/w/cpp/types/extent -template<typename T, size_t N> +//template<typename T, std::size_t N> +//static inline constexpr +//std::size_t SizeOfArray(const T(&)[N]) { +// return N; +//} + +/* +namespace { + template<class T> struct identity { using type = T; }; +} +template<typename R, typename T, std::size_t N> +static inline constexpr +typename identity<R>::type SizeOfArray(const T(&)[N]) { + static_assert(std::numeric_limits<R>::max() >= N, "N does not fit in R"); + return static_cast<R>(N); +} +*/ + +template<typename R = std::size_t, typename T, std::size_t N> static inline constexpr -size_t SizeOfArray(const T(&)[N]) { - return N; +R SizeOfArray(const T(&)[N]) { + static_assert(std::numeric_limits<R>::max() >= N, "N does not fit in R"); + return static_cast<R>(N); } #endif diff --git a/playground/include/stm32f10x_conf.h b/playground/include/stm32f10x_conf.h index f663d12..8c49c5e 100644 --- a/playground/include/stm32f10x_conf.h +++ b/playground/include/stm32f10x_conf.h @@ -30,7 +30,13 @@ #ifdef USE_FULL_ASSERT #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) +#ifdef __cplusplus +extern "C" { +#endif void assert_failed(uint8_t* file, uint32_t line); +#ifdef __cplusplus +} +#endif #else #define assert_param(expr) ((void)0) #endif |