diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2026-06-29 22:00:26 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2026-06-29 22:00:26 +0200 |
| commit | 82620f74d6e40617b725dcb8e50cdd94eb3e3e86 (patch) | |
| tree | f3c7e118b85cdf711617a1c1b82f61545c6ccd6c /utilities.hpp | |
| parent | d7c2a8029c4aefc295719174a863129645d6ab99 (diff) | |
| download | throttle-quadrant-82620f74d6e40617b725dcb8e50cdd94eb3e3e86.tar.xz throttle-quadrant-82620f74d6e40617b725dcb8e50cdd94eb3e3e86.zip | |
Diffstat (limited to 'utilities.hpp')
| -rw-r--r-- | utilities.hpp | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/utilities.hpp b/utilities.hpp deleted file mode 100644 index 819c170..0000000 --- a/utilities.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef THROTTLE_QUADRANT_UTILITIES_HPP -#define THROTTLE_QUADRANT_UTILITIES_HPP - -#include <Arduino.h> - -void* operator new(size_t size, void* ptr); - -namespace tq { - -template<typename ValueType> -struct optional { - - optional() - : m_engaged{ false } { - } - - optional(optional const& other) - : m_engaged{ other.has_value() } { - if (m_engaged) { - construct_from(other.value()); - } - } - - explicit optional(ValueType const& value) - : m_engaged{ true } { - construct_from(value); - } - - ~optional() { - destroy(); - } - - auto operator=(optional const& other) -> optional& { - destroy(); - m_engaged = other.m_engaged; - if (m_engaged) { - construct_from(other.value()); - } - } - - auto has_value() const -> bool { - return m_engaged; - } - - auto value() const -> ValueType const& { - return *(reinterpret_cast<ValueType const*>(m_storage)); - } - -private: - auto construct_from(ValueType const& value) -> void { - new (static_cast<byte*>(m_storage)) ValueType{ value }; - } - - auto destroy() -> void { - if (has_value()) { - (reinterpret_cast<ValueType const*>(m_storage))->~ValueType(); - } - } - - alignas(ValueType) byte m_storage[sizeof(ValueType)]; - bool m_engaged; -}; - - -} - -#endif
\ No newline at end of file |
