Merge commit 'c0baf7efca0e4c3a86a018ad2564d9df7b07c133'
(synced from d7f309750e)
This commit is contained in:
@@ -147,4 +147,19 @@ constexpr auto ModelTypeName_v = getModelTypeName<T, Str>();
|
|||||||
template<typename T, typename Str = const char*>
|
template<typename T, typename Str = const char*>
|
||||||
constexpr auto ModelTypeVersion_v = requireModelTypeVersion<T>();
|
constexpr auto ModelTypeVersion_v = requireModelTypeVersion<T>();
|
||||||
|
|
||||||
|
template<typename T, typename Str = const char*>
|
||||||
|
constexpr auto ModelTypeVersionStr_v = [] {
|
||||||
|
constexpr auto version = ModelTypeVersion_v<T>;
|
||||||
|
constexpr auto versionStr = ox::sfmt("{}", version);
|
||||||
|
return ox::BString<versionStr.len()>{versionStr};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr auto ModelTypeId_v = [] {
|
||||||
|
constexpr auto name = ModelTypeName_v<T, ox::StringView>;
|
||||||
|
constexpr auto version = ModelTypeVersion_v<T>;
|
||||||
|
constexpr auto versionStr = ox::sfmt<ox::BString<19>>("{}", version);
|
||||||
|
return ox::sfmt<ox::BString<name.len() + versionStr.len() + 1>>("{};{}", name, versionStr);
|
||||||
|
}();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ install(
|
|||||||
hardware.hpp
|
hardware.hpp
|
||||||
hashmap.hpp
|
hashmap.hpp
|
||||||
heapmgr.hpp
|
heapmgr.hpp
|
||||||
|
ignore.hpp
|
||||||
iterator.hpp
|
iterator.hpp
|
||||||
math.hpp
|
math.hpp
|
||||||
maybeview.hpp
|
maybeview.hpp
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ class FmtArg {
|
|||||||
char dataStr[10] = {};
|
char dataStr[10] = {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static StringView sv(const T &v, char *dataStr) noexcept {
|
constexpr StringView sv(const T &v, char *dataStr) noexcept {
|
||||||
if constexpr(is_bool_v<T>) {
|
if constexpr(is_bool_v<T>) {
|
||||||
return v ? "true" : "false";
|
return v ? "true" : "false";
|
||||||
} else if constexpr(is_integer_v<T>) {
|
} else if constexpr(is_integer_v<T>) {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if __has_include(<tuple>)
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
|
||||||
|
inline constexpr struct {
|
||||||
|
constexpr void operator=(auto&&) const noexcept {}
|
||||||
|
} ignore;
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -11,5 +11,5 @@
|
|||||||
#if __has_include(<cassert>)
|
#if __has_include(<cassert>)
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#else
|
#else
|
||||||
#define assert(e) while (1);
|
#define assert(e) while (!(e));
|
||||||
#endif
|
#endif
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "hardware.hpp"
|
#include "hardware.hpp"
|
||||||
#include "hashmap.hpp"
|
#include "hashmap.hpp"
|
||||||
#include "heapmgr.hpp"
|
#include "heapmgr.hpp"
|
||||||
|
#include "ignore.hpp"
|
||||||
#include "iterator.hpp"
|
#include "iterator.hpp"
|
||||||
#include "math.hpp"
|
#include "math.hpp"
|
||||||
#include "maybeview.hpp"
|
#include "maybeview.hpp"
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept {
|
|||||||
return base.len() >= endingLen && ox::strcmp(base.data() + (base.len() - endingLen), ending) == 0;
|
return base.len() >= endingLen && ox::strcmp(base.data() + (base.len() - endingLen), ending) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr std::size_t find(CRStringView str, char search) noexcept {
|
constexpr std::size_t find(CRStringView str, char search) noexcept {
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
for (; i < str.len(); ++i) {
|
for (; i < str.len(); ++i) {
|
||||||
@@ -90,6 +91,7 @@ constexpr std::size_t find(CRStringView str, char search) noexcept {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
constexpr std::size_t find(CRStringView str, CRStringView search) noexcept {
|
constexpr std::size_t find(CRStringView str, CRStringView search) noexcept {
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
for (; i < str.len(); ++i) {
|
for (; i < str.len(); ++i) {
|
||||||
@@ -101,6 +103,7 @@ constexpr std::size_t find(CRStringView str, CRStringView search) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t smallSz = 0>
|
template<std::size_t smallSz = 0>
|
||||||
|
[[nodiscard]]
|
||||||
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, char del) noexcept {
|
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, char del) noexcept {
|
||||||
ox::Vector<ox::StringView, smallSz> out;
|
ox::Vector<ox::StringView, smallSz> out;
|
||||||
constexpr auto nextSeg = [](CRStringView current, char del) {
|
constexpr auto nextSeg = [](CRStringView current, char del) {
|
||||||
@@ -117,6 +120,7 @@ constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, char del)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t smallSz = 0>
|
template<std::size_t smallSz = 0>
|
||||||
|
[[nodiscard]]
|
||||||
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, CRStringView del) noexcept {
|
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, CRStringView del) noexcept {
|
||||||
ox::Vector<ox::StringView, smallSz> out;
|
ox::Vector<ox::StringView, smallSz> out;
|
||||||
constexpr auto nextSeg = [](CRStringView current, CRStringView del) {
|
constexpr auto nextSeg = [](CRStringView current, CRStringView del) {
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ template<typename T>
|
|||||||
constexpr bool memberable(...) { return false; }
|
constexpr bool memberable(...) { return false; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_class: integral_constant<bool, !is_union<T>::value && memberable<T>(0)> {};
|
struct is_class: integral_constant<bool, !is_union_v<T> && memberable<T>(nullptr)> {};
|
||||||
|
|
||||||
namespace test {
|
namespace test {
|
||||||
struct TestClass {int i;};
|
struct TestClass {int i;};
|
||||||
@@ -159,11 +159,11 @@ constexpr bool is_class_v = is_class<T>();
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr bool is_signed_v = integral_constant<bool, T(-1) < T(0)>::value;
|
constexpr bool is_signed_v = integral_constant<bool, T(-1) < T(0)>::value;
|
||||||
|
|
||||||
template<typename T, std::size_t bits>
|
template<typename T, std::size_t bits = sizeof(T) * 8>
|
||||||
concept Signed_c = is_signed_v<T> && sizeof(T) == 8 * bits;
|
concept Signed_c = is_signed_v<T> && sizeof(T) == bits / 8;
|
||||||
|
|
||||||
template<typename T, std::size_t bits>
|
template<typename T, std::size_t bits = sizeof(T) * 8>
|
||||||
concept Unsigned_c = !is_signed_v<T> && sizeof(T) == 8 * bits;
|
concept Unsigned_c = !is_signed_v<T> && sizeof(T) == bits / 8;
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
struct is_same: false_type {};
|
struct is_same: false_type {};
|
||||||
|
|||||||
+20
-14
@@ -52,13 +52,15 @@ struct VectorAllocator {
|
|||||||
const std::size_t cap) noexcept {
|
const std::size_t cap) noexcept {
|
||||||
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
|
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
|
||||||
// try removing it later
|
// try removing it later
|
||||||
if (cap <= m_data.size() && count <= m_data.size()) {
|
if (!std::is_constant_evaluated()) {
|
||||||
for (auto i = 0u; i < count; ++i) {
|
if (cap <= m_data.size() && count <= m_data.size()) {
|
||||||
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
|
for (auto i = 0u; i < count; ++i) {
|
||||||
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
|
const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
|
||||||
std::construct_at<T>(dstItem, std::move(*srcItem));
|
const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
|
||||||
|
std::construct_at<T>(dstItem, std::move(*srcItem));
|
||||||
|
}
|
||||||
|
*items = reinterpret_cast<T*>(m_data.data());
|
||||||
}
|
}
|
||||||
*items = reinterpret_cast<T*>(m_data.data());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,20 +71,24 @@ struct VectorAllocator {
|
|||||||
const std::size_t cap) noexcept {
|
const std::size_t cap) noexcept {
|
||||||
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
|
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
|
||||||
// try removing it later
|
// try removing it later
|
||||||
if (cap <= m_data.size() && count <= m_data.size()) {
|
if (!std::is_constant_evaluated()) {
|
||||||
for (std::size_t i = 0; i < count; ++i) {
|
if (cap <= m_data.size() && count <= m_data.size()) {
|
||||||
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
|
for (std::size_t i = 0; i < count; ++i) {
|
||||||
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
|
const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
|
||||||
*dstItem = std::move(*srcItem);
|
const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
|
||||||
|
*dstItem = std::move(*srcItem);
|
||||||
|
}
|
||||||
|
*items = reinterpret_cast<T*>(m_data.data());
|
||||||
}
|
}
|
||||||
*items = reinterpret_cast<T*>(m_data.data());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void deallocate(T *items, std::size_t cap) noexcept {
|
constexpr void deallocate(T *items, std::size_t cap) noexcept {
|
||||||
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
|
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
|
||||||
if (std::is_constant_evaluated() || (items && static_cast<void*>(items) != static_cast<void*>(m_data.data()))) {
|
if (std::is_constant_evaluated()) {
|
||||||
m_allocator.deallocate(items, cap);
|
if (items && static_cast<void*>(items) != static_cast<void*>(m_data.data())) {
|
||||||
|
m_allocator.deallocate(items, cap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user