feat: add timer calibration

This commit is contained in:
Katharina 2026-07-02 22:38:16 +02:00
parent da848544c0
commit 43c87e5904
5 changed files with 144 additions and 5 deletions

View file

@ -9,6 +9,9 @@
// instead of <utility>. The CrackOS3 value_or_panic() helper is omitted because
// there is no global panic() in this tree yet.
struct nullopt_t {};
inline constexpr nullopt_t nullopt{};
template<typename T>
struct optional {
private:
@ -26,6 +29,7 @@ public:
using value_type = T;
constexpr optional() : initialized(false) {}
constexpr optional(nullopt_t) : initialized(false) {}
optional(const T& value) : initialized(true) {
new (buffer) T(value);
}
@ -135,10 +139,45 @@ public:
return !initialized;
}
template<typename R, typename Func, typename... ArgT>
optional<R> map(Func func, ArgT... args) {
template<typename Func>
auto map(Func&& func) -> optional<decltype(func(value()))> {
if (initialized) {
return func(value(), forward<ArgT>(args)...);
return func(value());
} else {
return {};
}
}
template<typename Func>
auto map(Func&& func) const -> optional<decltype(func(value()))> {
if (initialized) {
return func(value());
} else {
return {};
}
}
template<typename Func>
optional or_else(Func&& func) const {
if (initialized) {
return *this;
}
return func();
}
template<typename Func>
auto bind(Func&& func) -> decltype(func(value())) {
if (initialized) {
return func(value());
} else {
return {};
}
}
template<typename Func>
auto bind(Func&& func) const -> decltype(func(value())) {
if (initialized) {
return func(value());
} else {
return {};
}