Device interface library for multiple platforms including Mbed.

Dependents:   DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#

Maxim Interface is a library framework focused on providing flexible and expressive hardware interfaces. Both communication interfaces such as I2C and 1-Wire and device interfaces such as DS18B20 are supported. Modern C++ concepts are used extensively while keeping compatibility with C++98/C++03 and requiring no external dependencies. The embedded-friendly design does not depend on exceptions or RTTI.

The full version of the project is hosted on GitLab: https://gitlab.com/iabenz/MaximInterface

Revision:
11:3f3bf6bf5e6c
Parent:
8:5ea891c7d1a1
diff -r 947d3f44e0a0 -r 3f3bf6bf5e6c MaximInterfaceCore/array.hpp
--- a/MaximInterfaceCore/array.hpp	Mon Sep 30 09:39:32 2019 -0500
+++ b/MaximInterfaceCore/array.hpp	Tue Dec 03 10:52:28 2019 -0600
@@ -37,6 +37,7 @@
 #include <stdint.h>
 #include <algorithm>
 #include <iterator>
+#include "type_traits.hpp"
 
 namespace MaximInterfaceCore {
 
@@ -75,13 +76,13 @@
     return const_cast<reference>(static_cast<const array &>(*this).back());
   }
 
-  const_reference back() const { return operator[](size() - 1); }
+  const_reference back() const { return operator[](N - 1); }
 
   pointer data() {
     return const_cast<pointer>(static_cast<const array &>(*this).data());
   }
 
-  const_pointer data() const { return _buffer; }
+  const_pointer data() const { return reinterpret_cast<const_pointer>(&data_); }
 
   /// @}
 
@@ -102,7 +103,7 @@
 
   const_iterator end() const { return cend(); }
 
-  const_iterator cend() const { return cbegin() + size(); }
+  const_iterator cend() const { return cbegin() + N; }
 
   reverse_iterator rbegin() { return reverse_iterator(end()); }
 
@@ -125,11 +126,11 @@
   /// @name Capacity
   /// @{
 
-  static bool empty() { return size() == 0; }
+  static bool empty() { return N == 0; }
 
   static size_type size() { return N; }
 
-  static size_type max_size() { return size(); }
+  static size_type max_size() { return N; }
 
   /// @}
 
@@ -144,42 +145,42 @@
 
   /// @private
   /// @note Implementation detail set public to allow aggregate initialization.
-  T _buffer[N];
+  typename conditional<N == 0, char, T[N]>::type data_;
 };
 
 template <typename T, size_t N>
-inline bool operator==(const array<T, N> & lhs, const array<T, N> & rhs) {
+bool operator==(const array<T, N> & lhs, const array<T, N> & rhs) {
   return std::equal(lhs.begin(), lhs.end(), rhs.begin());
 }
 
 template <typename T, size_t N>
-inline bool operator!=(const array<T, N> & lhs, const array<T, N> & rhs) {
+bool operator!=(const array<T, N> & lhs, const array<T, N> & rhs) {
   return !operator==(lhs, rhs);
 }
 
 template <typename T, size_t N>
-inline bool operator<(const array<T, N> & lhs, const array<T, N> & rhs) {
+bool operator<(const array<T, N> & lhs, const array<T, N> & rhs) {
   return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(),
                                       rhs.end());
 }
 
 template <typename T, size_t N>
-inline bool operator>(const array<T, N> & lhs, const array<T, N> & rhs) {
+bool operator>(const array<T, N> & lhs, const array<T, N> & rhs) {
   return operator<(rhs, lhs);
 }
 
 template <typename T, size_t N>
-inline bool operator<=(const array<T, N> & lhs, const array<T, N> & rhs) {
+bool operator<=(const array<T, N> & lhs, const array<T, N> & rhs) {
   return !operator>(lhs, rhs);
 }
 
 template <typename T, size_t N>
-inline bool operator>=(const array<T, N> & lhs, const array<T, N> & rhs) {
+bool operator>=(const array<T, N> & lhs, const array<T, N> & rhs) {
   return !operator<(lhs, rhs);
 }
 
 template <typename T, size_t N>
-inline void swap(array<T, N> & lhs, array<T, N> & rhs) {
+void swap(array<T, N> & lhs, array<T, N> & rhs) {
   lhs.swap(rhs);
 }