aboutsummaryrefslogtreecommitdiff
path: root/playground/include
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-01-25 20:51:35 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2017-01-25 20:51:35 +0100
commit8a3fedbcb8fc58dae8b43db3cae39688ec0332ef (patch)
treeb148bde0a9191bc44e1f7ace5dada5ac4677bec3 /playground/include
parentb485617e1578ade7cb02e65a674d56315098b18c (diff)
downloadstm32f103-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')
-rw-r--r--playground/include/playground.h29
-rw-r--r--playground/include/stm32f10x_conf.h6
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