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.
This commit is contained in:
PixelyIon 2021-12-28 12:17:35 +05:30
parent c11962e8e4
commit 97cfcba0da

View File

@ -27,6 +27,8 @@ namespace skyline {
*/
constexpr span(T &spn) : std::span<T, Extent>(&spn, 1) {}
constexpr span(nullptr_t) : std::span<T, Extent>() {}
/**
* @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<T, Extent>& other) const {