ref: update formatting

This commit is contained in:
Katharina 2026-07-02 19:38:45 +02:00
parent 7d0155d8ce
commit ee097d6cdf
16 changed files with 419 additions and 420 deletions

View file

@ -17,7 +17,7 @@ private:
void destroy() {
if (initialized) {
((T*) buffer)->~T();
((T*)buffer)->~T();
initialized = false;
}
}
@ -26,12 +26,8 @@ public:
using value_type = T;
constexpr optional() : initialized(false) {}
optional(const T& value) : initialized(true) {
new (buffer) T(value);
}
optional(T&& value) : initialized(true) {
new (buffer) T(move(value));
}
optional(const T& value) : initialized(true) { new (buffer) T(value); }
optional(T&& value) : initialized(true) { new (buffer) T(move(value)); }
optional(const optional& other) : initialized(other.initialized) {
if (initialized) {
@ -46,28 +42,19 @@ public:
other.initialized = false;
}
~optional() {
destroy();
}
~optional() { destroy(); }
T* operator->() {
return (T*) buffer;
}
T* operator->() { return (T*)buffer; }
T& operator*() {
return *((T*) buffer);
}
T& operator*() { return *((T*)buffer); }
const T* operator->() const {
return (const T*) buffer;
}
const T* operator->() const { return (const T*)buffer; }
const T& operator*() const {
return *((const T*) buffer);
}
const T& operator*() const { return *((const T*)buffer); }
optional& operator=(const optional& other) {
if (this == &other) return *this;
if (this == &other)
return *this;
destroy();
if (other.initialized) {
new (buffer) T(*other);
@ -77,7 +64,8 @@ public:
}
optional& operator=(optional&& other) noexcept {
if (this == &other) return *this;
if (this == &other)
return *this;
destroy();
if (other.initialized) {
new (buffer) T(move(*other));
@ -87,17 +75,11 @@ public:
return *this;
}
[[nodiscard]] bool has_value() const {
return initialized;
}
[[nodiscard]] bool has_value() const { return initialized; }
T& value() {
return *((T*) buffer);
}
T& value() { return *((T*)buffer); }
const T& value() const {
return *((const T*) buffer);
}
const T& value() const { return *((const T*)buffer); }
template<typename Func, typename... ArgT>
T value_or_create(Func func, ArgT... args) {
@ -119,19 +101,15 @@ public:
const T& value_or(const T& default_value) const {
if (initialized) {
return *((const T*) buffer);
return *((const T*)buffer);
} else {
return default_value;
}
}
operator bool() const {
return initialized;
}
operator bool() const { return initialized; }
bool operator!() const {
return !initialized;
}
bool operator!() const { return !initialized; }
template<typename R, typename Func, typename... ArgT>
optional<R> map(Func func, ArgT... args) {

View file

@ -3,11 +3,17 @@
// Minimal freestanding replacements for <utility> (no stdlib available).
template<typename T>
struct remove_reference { using type = T; };
struct remove_reference {
using type = T;
};
template<typename T>
struct remove_reference<T&> { using type = T; };
struct remove_reference<T&> {
using type = T;
};
template<typename T>
struct remove_reference<T&&> { using type = T; };
struct remove_reference<T&&> {
using type = T;
};
template<typename T>
using remove_reference_t = typename remove_reference<T>::type;