From 97cfcba0da50f108b412964ae31931b3963d74b6 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Tue, 28 Dec 2021 12:17:35 +0530 Subject: [PATCH] Add Nullability for Optional Semantics to `span` Nullability allow for optional semantics where a span may be explicitly invalidated with `nullptr` being used as a sentinel value for it and a boolean operator that allows trivial checking for if the span is valid or not. --- app/src/main/cpp/skyline/common/span.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/cpp/skyline/common/span.h b/app/src/main/cpp/skyline/common/span.h index f838c727..7aad8181 100644 --- a/app/src/main/cpp/skyline/common/span.h +++ b/app/src/main/cpp/skyline/common/span.h @@ -27,6 +27,8 @@ namespace skyline { */ constexpr span(T &spn) : std::span(&spn, 1) {} + constexpr span(nullptr_t) : std::span() {} + /** * @brief We want to support implicitly casting from std::string_view -> span as it's just a specialization of a data view which span is a generic form of, the opposite doesn't hold true as not all data held by a span is string data therefore the conversion isn't implicit there */ @@ -84,6 +86,13 @@ namespace skyline { return this->begin() <= other.begin() && this->end() >= other.end(); } + /** + * @return If the span is valid by not being null + */ + constexpr bool valid() { + return this->data() != nullptr; + } + /** Comparision operators for equality and binary searches **/ constexpr bool operator==(const span& other) const {