diff --git a/deps/ox/src/ox/fs/test/tests.cpp b/deps/ox/src/ox/fs/test/tests.cpp index 902790b5..f5b6db98 100644 --- a/deps/ox/src/ox/fs/test/tests.cpp +++ b/deps/ox/src/ox/fs/test/tests.cpp @@ -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(argc)}; + auto const args = ox::Span{argv, static_cast(argc)}; ox::StringView const testName = args[1]; ox::StringView const testArg = argc >= 3 ? args[2] : nullptr; auto const func = tests.find(testName); diff --git a/deps/ox/src/ox/fs/tool.cpp b/deps/ox/src/ox/fs/tool.cpp index 6c2767d2..c65819fb 100644 --- a/deps/ox/src/ox/fs/tool.cpp +++ b/deps/ox/src/ox/fs/tool.cpp @@ -39,7 +39,7 @@ static ox::Result> loadFs(const char *path) noexce return {ox::make_unique(buff.data, buff.size)}; } -static ox::Error runLs(ox::FileSystem *fs, ox::SpanView args) noexcept { +static ox::Error runLs(ox::FileSystem *fs, ox::Span 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 args) noexc return OxError(0); } -static ox::Error runRead(ox::FileSystem *fs, ox::SpanView args) noexcept { +static ox::Error runRead(ox::FileSystem *fs, ox::Span 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(argc)}; + auto const args = ox::Span{argv, static_cast(argc)}; auto const fsPath = args[1]; ox::String subCmd(args[2]); oxRequire(fs, loadFs(fsPath)); diff --git a/deps/ox/src/ox/std/buffer.hpp b/deps/ox/src/ox/std/buffer.hpp index 4dfef6a1..b33b7bee 100644 --- a/deps/ox/src/ox/std/buffer.hpp +++ b/deps/ox/src/ox/std/buffer.hpp @@ -21,7 +21,7 @@ namespace ox { extern template class Vector; using Buffer = Vector; -using BufferView = SpanView; +using BufferView = Span; class BufferWriter { private: diff --git a/deps/ox/src/ox/std/span.hpp b/deps/ox/src/ox/std/span.hpp index 67a47c48..c4ad680f 100644 --- a/deps/ox/src/ox/std/span.hpp +++ b/deps/ox/src/ox/std/span.hpp @@ -18,126 +18,6 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage) namespace ox { -template -class SpanView { - - private: - T const*m_items{}; - std::size_t m_size{}; - - public: - using value_type = T; - using size_type = std::size_t; - - template - using iterator = SpanIterator; - - constexpr SpanView() noexcept {} - - template - constexpr SpanView(ox::Array const&a) noexcept: - m_items(a.data()), - m_size(a.size()) { - } - - template - constexpr SpanView(ox::Vector const&v) noexcept: - m_items(v.data()), - m_size(v.size()) { - } - - template - 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 begin() const noexcept { - return iterator(m_items, 0, m_size); - } - - [[nodiscard]] - constexpr iterator end() const noexcept { - return iterator(m_items, m_size, m_size); - } - - [[nodiscard]] - constexpr iterator cbegin() const noexcept { - return iterator(m_items, 0, m_size); - } - - [[nodiscard]] - constexpr iterator cend() const noexcept { - return iterator(m_items, m_size, m_size); - } - - [[nodiscard]] - constexpr iterator crbegin() const noexcept { - return iterator(m_items, m_size - 1, m_size); - } - - [[nodiscard]] - constexpr iterator crend() const noexcept { - return iterator(m_items, MaxValue, m_size); - } - - [[nodiscard]] - constexpr iterator rbegin() const noexcept { - return iterator(m_items, m_size - 1, m_size); - } - - [[nodiscard]] - constexpr iterator rend() const noexcept { - return iterator(m_items, MaxValue, 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 class Span { @@ -153,18 +33,32 @@ class Span { template using iterator = SpanIterator; + constexpr Span() noexcept = default; + template constexpr Span(ox::Array &a) noexcept: m_items(a.data()), m_size(a.size()) { } + template + constexpr Span(ox::Array, sz> const&a) noexcept: + m_items(a.data()), + m_size(a.size()) { + } + template constexpr Span(ox::Vector &v) noexcept: m_items(v.data()), m_size(v.size()) { } + template + constexpr Span(ox::Vector, sz, Allocator> const&v) noexcept: + m_items(v.data()), + m_size(v.size()) { + } + template constexpr Span(T (&a)[sz]) noexcept: m_items(a), @@ -273,6 +167,9 @@ class Span { }; +template +using SpanView = Span; + } OX_CLANG_NOWARN_END diff --git a/deps/ox/src/ox/std/test/tests.cpp b/deps/ox/src/ox/std/test/tests.cpp index 2f734291..4aecb7ce 100644 --- a/deps/ox/src/ox/std/test/tests.cpp +++ b/deps/ox/src/ox/std/test/tests.cpp @@ -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(argc)}; + auto const args = ox::Span{argv, static_cast(argc)}; auto const testName = args[1]; auto const func = tests.find(testName); if (func != tests.end()) { diff --git a/deps/ox/src/ox/std/typetraits.hpp b/deps/ox/src/ox/std/typetraits.hpp index 9207babc..6202efb5 100644 --- a/deps/ox/src/ox/std/typetraits.hpp +++ b/deps/ox/src/ox/std/typetraits.hpp @@ -269,6 +269,41 @@ template constexpr bool is_move_constructible_v = detail::is_move_constructible(0); +template +struct remove_cv { + using type = T; +}; + +template +struct remove_cv { + using type = T; +}; + +template +struct remove_cv { + using type = T; +}; + +template +struct remove_cv { + using type = T; +}; + + +template +struct remove_const { + using type = T; +}; + +template +struct remove_const { + using type = T; +}; + +template +using remove_const_t = typename remove_const::type; + + // is String? template diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 229c2d17..7bdaf522 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -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&) noexcept { } -OX_CLANG_NOWARN_END +OX_ALLOW_UNSAFE_BUFFERS_END