[ox] Replace SpanView with Span<const T>
This commit is contained in:
parent
1bf4f246c2
commit
b14f1d5000
2
deps/ox/src/ox/fs/test/tests.cpp
vendored
2
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -231,7 +231,7 @@ int main(int argc, const char **argv) {
|
||||
oxError("Must specify test to run");
|
||||
return -1;
|
||||
}
|
||||
auto const args = ox::SpanView{argv, static_cast<size_t>(argc)};
|
||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||
ox::StringView const testName = args[1];
|
||||
ox::StringView const testArg = argc >= 3 ? args[2] : nullptr;
|
||||
auto const func = tests.find(testName);
|
||||
|
6
deps/ox/src/ox/fs/tool.cpp
vendored
6
deps/ox/src/ox/fs/tool.cpp
vendored
@ -39,7 +39,7 @@ static ox::Result<ox::UniquePtr<ox::FileSystem>> loadFs(const char *path) noexce
|
||||
return {ox::make_unique<ox::FileSystem32>(buff.data, buff.size)};
|
||||
}
|
||||
|
||||
static ox::Error runLs(ox::FileSystem *fs, ox::SpanView<const char*> args) noexcept {
|
||||
static ox::Error runLs(ox::FileSystem *fs, ox::Span<const char*> args) noexcept {
|
||||
if (args.size() < 2) {
|
||||
oxErr("Must provide a directory to ls\n");
|
||||
return OxError(1);
|
||||
@ -51,7 +51,7 @@ static ox::Error runLs(ox::FileSystem *fs, ox::SpanView<const char*> args) noexc
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
static ox::Error runRead(ox::FileSystem *fs, ox::SpanView<const char*> args) noexcept {
|
||||
static ox::Error runRead(ox::FileSystem *fs, ox::Span<const char*> args) noexcept {
|
||||
if (args.size() < 2) {
|
||||
oxErr("Must provide a path to a file to read\n");
|
||||
return OxError(1);
|
||||
@ -66,7 +66,7 @@ static ox::Error run(int argc, const char **argv) noexcept {
|
||||
oxErr("OxFS file and subcommand arguments are required\n");
|
||||
return OxError(1);
|
||||
}
|
||||
auto const args = ox::SpanView{argv, static_cast<size_t>(argc)};
|
||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||
auto const fsPath = args[1];
|
||||
ox::String subCmd(args[2]);
|
||||
oxRequire(fs, loadFs(fsPath));
|
||||
|
2
deps/ox/src/ox/std/buffer.hpp
vendored
2
deps/ox/src/ox/std/buffer.hpp
vendored
@ -21,7 +21,7 @@ namespace ox {
|
||||
extern template class Vector<char>;
|
||||
|
||||
using Buffer = Vector<char>;
|
||||
using BufferView = SpanView<char>;
|
||||
using BufferView = Span<const char>;
|
||||
|
||||
class BufferWriter {
|
||||
private:
|
||||
|
137
deps/ox/src/ox/std/span.hpp
vendored
137
deps/ox/src/ox/std/span.hpp
vendored
@ -18,126 +18,6 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<typename T>
|
||||
class SpanView {
|
||||
|
||||
private:
|
||||
T const*m_items{};
|
||||
std::size_t m_size{};
|
||||
|
||||
public:
|
||||
using value_type = T;
|
||||
using size_type = std::size_t;
|
||||
|
||||
template<typename RefType = T const&, typename PtrType = T const*, bool reverse = false>
|
||||
using iterator = SpanIterator<T, RefType, PtrType, reverse>;
|
||||
|
||||
constexpr SpanView() noexcept {}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr SpanView(ox::Array<T, sz> const&a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz, typename Allocator>
|
||||
constexpr SpanView(ox::Vector<T, sz, Allocator> const&v) noexcept:
|
||||
m_items(v.data()),
|
||||
m_size(v.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr SpanView(const T (&a)[sz]) noexcept:
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
}
|
||||
|
||||
constexpr SpanView(const T *a, std::size_t sz) noexcept:
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
}
|
||||
|
||||
constexpr iterator<> begin() noexcept {
|
||||
return iterator<>(m_items, 0, m_size);
|
||||
}
|
||||
|
||||
constexpr iterator<> end() noexcept {
|
||||
return iterator<>(m_items, m_size, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> begin() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, 0, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> end() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> cbegin() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, 0, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> cend() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> crbegin() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> crend() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> rbegin() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> rend() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||
}
|
||||
|
||||
constexpr const T &operator[](std::size_t i) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
constexpr SpanView operator+(size_t i) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
return {m_items + i, m_size - i};
|
||||
}
|
||||
|
||||
constexpr SpanView operator+=(size_t i) noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
m_items += i;
|
||||
m_size -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T const*data() const noexcept {
|
||||
return m_items;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool empty() const noexcept {
|
||||
return m_size == 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Span {
|
||||
@ -153,18 +33,32 @@ class Span {
|
||||
template<typename RefType = T&, typename PtrType = T*, bool reverse = false>
|
||||
using iterator = SpanIterator<T, RefType, PtrType, reverse>;
|
||||
|
||||
constexpr Span() noexcept = default;
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(ox::Array<T, sz> &a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(ox::Array<ox::remove_const_t<T>, sz> const&a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz, typename Allocator>
|
||||
constexpr Span(ox::Vector<T, sz, Allocator> &v) noexcept:
|
||||
m_items(v.data()),
|
||||
m_size(v.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz, typename Allocator>
|
||||
constexpr Span(ox::Vector<ox::remove_const_t<T>, sz, Allocator> const&v) noexcept:
|
||||
m_items(v.data()),
|
||||
m_size(v.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr Span(T (&a)[sz]) noexcept:
|
||||
m_items(a),
|
||||
@ -273,6 +167,9 @@ class Span {
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using SpanView = Span<const T>;
|
||||
|
||||
}
|
||||
|
||||
OX_CLANG_NOWARN_END
|
||||
|
2
deps/ox/src/ox/std/test/tests.cpp
vendored
2
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -477,7 +477,7 @@ int main(int argc, const char **argv) {
|
||||
oxError("Must specify test to run");
|
||||
return -1;
|
||||
}
|
||||
auto const args = ox::SpanView{argv, static_cast<size_t>(argc)};
|
||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
|
35
deps/ox/src/ox/std/typetraits.hpp
vendored
35
deps/ox/src/ox/std/typetraits.hpp
vendored
@ -269,6 +269,41 @@ template<class T>
|
||||
constexpr bool is_move_constructible_v = detail::is_move_constructible<T>(0);
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct remove_cv {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct remove_cv<const T> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct remove_cv<volatile T> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct remove_cv<const volatile T> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct remove_const {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct remove_const<const T> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using remove_const_t = typename remove_const<T>::type;
|
||||
|
||||
|
||||
// is String?
|
||||
|
||||
template<std::size_t SmallStringSize>
|
||||
|
4
deps/ox/src/ox/std/vector.hpp
vendored
4
deps/ox/src/ox/std/vector.hpp
vendored
@ -20,7 +20,7 @@
|
||||
#include "types.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
namespace ox {
|
||||
|
||||
@ -712,4 +712,4 @@ constexpr auto alignOf(const Vector<T>&) noexcept {
|
||||
|
||||
}
|
||||
|
||||
OX_CLANG_NOWARN_END
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
Loading…
Reference in New Issue
Block a user