[ox/std] Add spancpy
This commit is contained in:
parent
861d177a27
commit
f7a468ea1e
20
deps/ox/src/ox/std/span.hpp
vendored
20
deps/ox/src/ox/std/span.hpp
vendored
@ -14,7 +14,7 @@
|
||||
#include "iterator.hpp"
|
||||
#include "vector.hpp"
|
||||
|
||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
|
||||
namespace ox {
|
||||
|
||||
@ -133,7 +133,7 @@ class Span {
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
constexpr const T &operator[](std::size_t i) const noexcept {
|
||||
constexpr T const&operator[](std::size_t i) const noexcept {
|
||||
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
@ -168,8 +168,20 @@ class Span {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using SpanView = Span<const T>;
|
||||
using SpanView = Span<T const>;
|
||||
|
||||
template<typename T>
|
||||
constexpr void spancpy(ox::Span<T> const dst, ox::SpanView<T> const src) noexcept {
|
||||
auto const sz = ox::min(dst.size(), src.size());
|
||||
if (std::is_constant_evaluated() || std::is_trivially_copyable_v<T>) {
|
||||
for (size_t i{}; i < sz; ++i) {
|
||||
dst.data()[i] = src.data()[i];
|
||||
}
|
||||
} else {
|
||||
memcpy(dst.data(), src.data(), sz * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OX_CLANG_NOWARN_END
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
10
deps/ox/src/ox/std/typetraits.hpp
vendored
10
deps/ox/src/ox/std/typetraits.hpp
vendored
@ -19,12 +19,15 @@
|
||||
namespace std {
|
||||
|
||||
template<typename T>
|
||||
constexpr bool is_union_v = __is_union(T);
|
||||
inline constexpr bool is_union_v = __is_union(T);
|
||||
|
||||
constexpr bool is_constant_evaluated() noexcept {
|
||||
inline constexpr bool is_constant_evaluated() noexcept {
|
||||
return __builtin_is_constant_evaluated();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(T);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -156,6 +159,9 @@ static_assert(is_class<int>::value == false);
|
||||
template<typename T>
|
||||
constexpr bool is_class_v = is_class<T>();
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_trivially_copyable_v = std::is_trivially_copyable_v<T>;
|
||||
|
||||
template<typename T>
|
||||
constexpr bool is_signed_v = integral_constant<bool, T(-1) < T(0)>::value;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user