diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-01-25 20:51:35 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-01-25 20:51:35 +0100 |
commit | 8a3fedbcb8fc58dae8b43db3cae39688ec0332ef (patch) | |
tree | b148bde0a9191bc44e1f7ace5dada5ac4677bec3 /playground/include/playground.h | |
parent | b485617e1578ade7cb02e65a674d56315098b18c (diff) | |
download | stm32f103-playground-8a3fedbcb8fc58dae8b43db3cae39688ec0332ef.tar.gz stm32f103-playground-8a3fedbcb8fc58dae8b43db3cae39688ec0332ef.tar.bz2 stm32f103-playground-8a3fedbcb8fc58dae8b43db3cae39688ec0332ef.tar.xz stm32f103-playground-8a3fedbcb8fc58dae8b43db3cae39688ec0332ef.zip |
o i2c test
o Misc other stuff.
Diffstat (limited to 'playground/include/playground.h')
-rw-r--r-- | playground/include/playground.h | 29 |
1 files changed, 26 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 |