C++20 Port #5

Merged
kayomn merged 35 commits from cpp-port into main 2023-02-20 02:33:45 +01:00
2 changed files with 11 additions and 6 deletions
Showing only changes of commit 3856a03ec1 - Show all commits

View File

@ -88,7 +88,7 @@ export namespace app {
if (path_remaining.length < file_path.byte_size()) return nullptr; if (path_remaining.length < file_path.byte_size()) return nullptr;
coral::copy(path_remaining, coral::slice{file_path.begin(), file_path.end()}.as_bytes()); coral::copy(path_remaining, file_path.as_slice().as_bytes());
return ::SDL_RWFromFile(reinterpret_cast<char const *>(this->path_buffer), "r"); return ::SDL_RWFromFile(reinterpret_cast<char const *>(this->path_buffer), "r");
} }

View File

@ -29,6 +29,13 @@ export namespace coral {
this->buffer[max] = max - text_size; this->buffer[max] = max - text_size;
} }
/**
* Returns a weak reference to the [path] as a [slice].
*/
constexpr slice<char const> as_slice() const {
return {this->buffer, this->byte_size()};
}
/** /**
* Returns the base pointer of the path name. * Returns the base pointer of the path name.
* *
@ -50,8 +57,7 @@ export namespace coral {
* they are identical. * they are identical.
*/ */
constexpr size compare(path const & that) const { constexpr size compare(path const & that) const {
return coral::compare(slice{this->begin(), this->end()}.as_bytes(), return coral::compare(this->as_slice().as_bytes(), that.as_slice().as_bytes());
slice{that.begin(), that.end()}.as_bytes());
} }
/** /**
@ -66,8 +72,7 @@ export namespace coral {
* otherwise `false`. * otherwise `false`.
*/ */
constexpr bool equals(path const & that) const { constexpr bool equals(path const & that) const {
return coral::equals(slice{this->begin(), this->end()}.as_bytes(), return coral::equals(this->as_slice().as_bytes(), that.as_slice().as_bytes());
slice{that.begin(), that.end()}.as_bytes());
} }
/** /**
@ -76,7 +81,7 @@ export namespace coral {
* *Note:* the returned hash code is not guaranteed to be unique. * *Note:* the returned hash code is not guaranteed to be unique.
*/ */
constexpr u64 hash() const { constexpr u64 hash() const {
return coral::hash(slice{this->begin(), this->end()}.as_bytes()); return coral::hash(this->as_slice().as_bytes());
} }
/** /**