Squashed 'deps/nostalgia/' changes from eed115b2..7d9f363b

7d9f363b [nostalgia/core/studio] Show color names in TileSheetEditor
ababc2a7 [nostalgia/core/studio] Add Name to colors table in PaletteEditor
bfd4bc3c [nostalgia/core] Revise Palette system, give TileSheetEditor a config file
8826d51e [studio] Add configio.hpp to studio.hpp
c021e5e7 [ox/oc] Fix OC not dealing with certain int types properly
7d8a8e0e [keel] Cleanup
95a69b72 [ox/std] Fix String::c_str to always retrun a valid C str
e4c38660 [nostalgia/core] Fix subsheet resize not to read garbage
67cf3ae8 [ox/std] Ensure ox::String always has at least a null terminator
2761f23d [nostalgia/developer-handbook] Update serialization notes
6c170d31 [nostalgia/developer-handbook] Update serialization notes
d20bfc77 [nostalgia/developer-handbook] Update serialization notes
07ecbde1 [nostalgia/developer-handbook] Update notes on error handling
fbe2fcd3 [nostalgia/developer-handbook] Update notes on error handling
a8bb99b6 [turbine] Remove ClipboardObject::typeMatches
667dd21a [turbine] Make ClipboardObject::typId return a StringView
5d89370c [turbine] Rework getClipboardObject to use ox::ModelTypeId_v
b968ec8a [keel] Remove redundant move
ec45ffb7 [studio] Fix build error
97dc0274 [nostalgia/core/studio] Add acceptsClipboardPayload to TileSheetEditor
a138f60f [studio] Add acceptsClipboardPayload to Editor
791d1950 [turbine] Make ClipboardObject use ox::ModelTypeId_v for typeId
78eb8fca [keel] Cleanup pack logging
0b8051b6 [ox/preloader] Fix alignment issue
5a426829 [nostalgia/core/studio] Cleanup TileSheet selection, fix copy/paste bug
9d2fe0e8 [studio] Add size function to Selection
f1894699 [keel] Remove setAsset
27b38ed2 [keel,studio] Fix hotloading for files that get loaded as multiple types
2bb7c514 [studio/modlib] Fix type desc writing logic inversion
5177cfb0 [studio/modlib] Make Project::mkdir only mkdir if dir does not exist
f9a14433 [studio/modlib] Add variant of ComboBox that takes callback
e62426b0 [keel] Ensure consistent asset IDs in AssetManager
af634bd4 [ox/fs] Add FileSystem::exists
49b859ec [studio/modlib] Give Selection constructors
19a41201 [studio/modlib] Make iterateSelection return errors properly
f69b8afa [nostalgia] Remove use of deleted function
9c98b5e2 [studio/modlib] Remove color.hpp
1f87216d [nostalgia/core] Add applySelectionColor
94c59604 [nostalgia/core/opengl] Fix for Ox changes
8ee016c1 [studio/modlib] Add SelectionTracker
dc20c667 [ox/std] Add conversion functions for geo types, cleanup
407e5424 [ox/std] Remove SmallMap dtor, replace timing code with steady_clock
3b188696 [ox/claw] Remove enum type from ClawFormat
0fab6c7c [ox/preloader] Remove debug code
a72b865d [studio/modlib] Add function for exporting selection color
c0479604 [studio,nostalgia/studio] Make executing UndoCommands report errors
a1c89906 [nostalgia/studio] Make UndoCommand undo/redo return ox::Error
7fb0549c [nostalgia/core] Revert some auto formatting done by CLion...
37e65ab0 [nostalgia/core/studio] Fix Subsheet width to update properly
9105b1ec [ox/std] Fix Linux build
fbeb0815 [ox/model] Fix type params in buildTypeId
b882a47e [ox/std] Fix resize to set null terminator
660f2f56 [ox/std] Rework FileReader into StreamReader
aa83c2a6 [nostalgia/core/studio] Remove some unnecessary copying
4a2b1fd7 [studio,keel] Make fileChanged emit UUID as well as path, add uuidUrlToUuid
08f958fb [ox/std] Add IntegerRange_c
a651d45a [ox/std] Fix Vector insert functions
9e9f317c [studio] Make UndoCommand::mergeWith take a reference
f5a02ce9 [nostalgia/core/gba] Fix build
6971c310 [studio] Add NoChangeException
c47f48eb [keel] Add/cleanup UUID/path lookup functions
76771e7b [nostalgia/core] Add tileColumns and tileRows functions
f6a0ae20 [ox/std] Fix some Windows warnings
752c8c1d [glutils] Fix type conversion that happened on Windows
af3bff1a [glutils] Add FrameBuffer::sizef
87416e13 [ox/std] Make MallocaPtr call destructor
047b4396 [ox/std] Make Point and Size members int32_t
40b8da4d [studio/modlib] Cleanup
123c4125 [ox/std] Add SmallMap::pairs(), SmallMap model
963ec5d3 [ox/std] Add operator-> to SpanIterator
6df77a23 [glutils] Add size function to FrameBuffer
df412cf8 [ox/std] Add missing typenames
ae30ef36 Merge commit 'b66cef7127e97269fc6072a6f66ccc08990f6d2e'
095a1135 Merge commit 'f48824793cfce315971fe2e699ece198c7a79407'
ce1836ab Merge commit '1e041bd2ebfe5ace7bed3906faf60345aa98a8bc'
7d1641fa Merge commit '420fa96463f59c4a4a7cd66b16b0ad01ab0d55e6'
423212b2 [studio] Add missing include
60da1063 Merge commit 'bd416f82e25f1b710ab2b7890274571dd3fcd53d'
60d1996f [keel] Minor optimization

git-subtree-dir: deps/nostalgia
git-subtree-split: 7d9f363bfa7a2c64f5c4bcfd0b6686f3f5678119
This commit is contained in:
2024-05-30 23:14:19 -05:00
parent b66cef7127
commit 76b8b03a2c
90 changed files with 1633 additions and 832 deletions

View File

@@ -96,6 +96,7 @@ install(
buildinfo.hpp
byteswap.hpp
concepts.hpp
conv.hpp
def.hpp
defer.hpp
defines.hpp

View File

@@ -32,7 +32,7 @@ constexpr To bit_cast(const From &src) noexcept requires(sizeof(To) == sizeof(Fr
namespace ox {
template<typename To, typename From>
constexpr typename enable_if<sizeof(To) == sizeof(From), To>::type cbit_cast(From src) noexcept {
constexpr To cbit_cast(From src) noexcept requires(sizeof(To) == sizeof(From)) {
To dst = {};
ox::memcpy(&dst, &src, sizeof(src));
return dst;

View File

@@ -8,6 +8,7 @@
#pragma once
#include "bit.hpp"
#include "typetraits.hpp"
namespace ox {
@@ -29,4 +30,6 @@ concept OxString_c = isOxString_v<T>;
template<typename T>
concept Integral_c = ox::is_integral_v<T>;
template<typename T, size_t max>
concept IntegerRange_c = ox::is_integer_v<T> && ox::MaxValue<T> >= max;
}

45
deps/ox/src/ox/std/conv.hpp vendored Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright 2015 - 2024 gary@drinkingtea.net
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "point.hpp"
#include "size.hpp"
#include "vec.hpp"
namespace ox {
constexpr Vec2::operator Point() const noexcept {
return {
static_cast<int32_t>(x),
static_cast<int32_t>(y),
};
}
constexpr Vec2::operator Size() const noexcept {
return {
static_cast<int32_t>(x),
static_cast<int32_t>(y),
};
}
constexpr Point::operator Vec2() const noexcept {
return {
static_cast<float>(x),
static_cast<float>(y),
};
}
constexpr Size::operator Vec2() const noexcept {
return {
static_cast<float>(width),
static_cast<float>(height),
};
}
}

View File

@@ -128,6 +128,10 @@ struct SpanIterator {
return operator-=(1);
}
constexpr PtrType operator->() const noexcept {
return &m_t[m_offset];
}
constexpr RefType operator*() const noexcept {
return m_t[m_offset];
}

View File

@@ -102,6 +102,7 @@ class MallocaPtr {
}
constexpr ~MallocaPtr() noexcept {
m_val->~T();
if (m_onHeap && m_val) {
delete[] reinterpret_cast<uint8_t*>(m_val);
}

View File

@@ -17,8 +17,8 @@ class Point {
public:
static constexpr auto TypeName = "net.drinkingtea.ox.Point";
static constexpr auto TypeVersion = 1;
int x = 0;
int y = 0;
int32_t x = 0;
int32_t y = 0;
constexpr Point() noexcept = default;
@@ -64,6 +64,7 @@ class Point {
constexpr bool operator!=(const Point&) const noexcept;
explicit constexpr operator class Vec2() const noexcept;
};
constexpr Point::Point(int x, int y) noexcept {

View File

@@ -8,7 +8,7 @@
#ifdef OX_USE_STDLIB
#include <cstdio>
#include <istream>
#include "array.hpp"
#include "reader.hpp"
@@ -16,41 +16,56 @@
namespace ox {
[[nodiscard]]
constexpr int sdMap(ox::ios_base::seekdir in) noexcept {
constexpr std::ios_base::seekdir sdMap(ox::ios_base::seekdir in) noexcept {
switch (in) {
case ox::ios_base::beg:
return SEEK_SET;
return std::ios_base::beg;
case ox::ios_base::end:
return SEEK_END;
return std::ios_base::end;
case ox::ios_base::cur:
return SEEK_CUR;
return std::ios_base::cur;
}
return -1;
return std::ios_base::beg;
}
ox::Result<char> FileReader::peek() const noexcept {
auto const c = fgetc(m_file);
auto const ok = c != EOF;
if (ok && ungetc(c, m_file)) [[unlikely]] {
return OxError(1, "Unable to unget character");
ox::Result<char> StreamReader::peek() const noexcept {
try {
char c{};
m_strm.get(c);
auto const ok = c != EOF;
if (ok && m_strm.unget()) [[unlikely]] {
return OxError(1, "Unable to unget character");
}
return {static_cast<char>(c), OxError(!ok, "File peek failed")};
} catch (std::exception const&) {
return OxError(1, "peek failed");
}
return {static_cast<char>(c), OxError(!ok, "File peek failed")};
}
ox::Result<std::size_t> FileReader::read(char *v, std::size_t cnt) noexcept {
return fread(v, 1, cnt, m_file);
ox::Result<std::size_t> StreamReader::read(char *v, std::size_t cnt) noexcept {
return static_cast<size_t>(m_strm.read(v, static_cast<std::streamsize>(cnt)).gcount());
}
ox::Error FileReader::seekg(std::size_t p) noexcept {
return OxError(fseek(m_file, static_cast<int64_t>(p), SEEK_CUR) != 0);
ox::Error StreamReader::seekg(std::size_t p) noexcept {
try {
m_strm.seekg(static_cast<long long int>(p), std::ios_base::cur);
} catch (std::exception const&) {
return OxError(1, "seekg failed");
}
return {};
}
ox::Error FileReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
return OxError(fseek(m_file, p, sdMap(sd)) != 0);
ox::Error StreamReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
try {
m_strm.seekg(p, sdMap(sd));
} catch (std::exception const&) {
return OxError(1, "seekg failed");
}
return {};
}
ox::Result<std::size_t> FileReader::tellg() noexcept {
const auto sz = ftell(m_file);
ox::Result<std::size_t> StreamReader::tellg() noexcept {
const auto sz = m_strm.tellg();
return {static_cast<std::size_t>(sz), OxError(sz == -1)};
}

View File

@@ -9,7 +9,7 @@
#pragma once
#ifdef OX_USE_STDLIB
#include <cstdio>
#include <istream>
#endif
#include "concepts.hpp"
@@ -65,11 +65,11 @@ class ReaderT: public Reader_v {
};
#ifdef OX_USE_STDLIB
class FileReader: public Reader_v {
class StreamReader: public Reader_v {
private:
FILE *m_file = nullptr;
std::istream &m_strm;
public:
constexpr explicit FileReader(FILE *file) noexcept: m_file(file) {}
constexpr explicit StreamReader(std::istream &stream) noexcept: m_strm(stream) {}
ox::Result<char> peek() const noexcept override;
ox::Result<std::size_t> read(char *v, std::size_t cnt) noexcept override;
ox::Error seekg(std::size_t p) noexcept override;

View File

@@ -17,8 +17,8 @@ class Size {
public:
static constexpr auto TypeName = "net.drinkingtea.ox.Size";
static constexpr auto TypeVersion = 1;
int width = 0;
int height = 0;
int32_t width = 0;
int32_t height = 0;
constexpr Size() noexcept = default;
@@ -64,6 +64,7 @@ class Size {
constexpr bool operator!=(const Size&) const noexcept;
explicit constexpr operator class Vec2() const noexcept;
};
constexpr Size::Size(int width, int height) noexcept {

View File

@@ -8,7 +8,7 @@
#pragma once
#include "algorithm.hpp"
#include "def.hpp"
#include "hash.hpp"
#include "ignore.hpp"
#include "stringview.hpp"
@@ -28,7 +28,7 @@ class SmallMap {
T value{};
};
private:
protected:
using PairVector = Vector<Pair, SmallSz>;
PairVector m_pairs;
@@ -39,8 +39,6 @@ class SmallMap {
constexpr SmallMap(SmallMap &&other) noexcept;
constexpr ~SmallMap();
constexpr bool operator==(SmallMap const&other) const;
constexpr SmallMap &operator=(SmallMap const&other);
@@ -79,6 +77,11 @@ class SmallMap {
[[nodiscard]]
constexpr Pair &get(size_t i) noexcept;
[[nodiscard]]
constexpr ox::SpanView<Pair> pairs() const noexcept {
return m_pairs;
}
constexpr void clear();
private:
@@ -100,11 +103,6 @@ constexpr SmallMap<K, T, SmallSz>::SmallMap(SmallMap<K, T, SmallSz> &&other) noe
m_pairs = std::move(other.m_pairs);
}
template<typename K, typename T, size_t SmallSz>
constexpr SmallMap<K, T, SmallSz>::~SmallMap() {
clear();
}
template<typename K, typename T, size_t SmallSz>
constexpr bool SmallMap<K, T, SmallSz>::operator==(SmallMap const&other) const {
return m_pairs == other.m_pairs;
@@ -204,12 +202,12 @@ constexpr T &SmallMap<K, T, SmallSz>::value(size_t i) noexcept {
}
template<typename K, typename T, size_t SmallSz>
constexpr SmallMap<K, T, SmallSz>::Pair const&SmallMap<K, T, SmallSz>::get(size_t i) const noexcept {
constexpr typename SmallMap<K, T, SmallSz>::Pair const&SmallMap<K, T, SmallSz>::get(size_t i) const noexcept {
return m_pairs[i];
}
template<typename K, typename T, size_t SmallSz>
constexpr SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::get(size_t i) noexcept {
constexpr typename SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::get(size_t i) noexcept {
return m_pairs[i];
}
@@ -246,4 +244,12 @@ constexpr typename SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::acces
return pairs.emplace_back();
}
template<typename T, typename K, typename V, size_t SmallSz>
constexpr Error model(T *io, ox::CommonPtrWith<SmallMap<K, V, SmallSz>> auto *obj) noexcept {
using Map = SmallMap<K, V, SmallSz>;
oxReturnError(io->template setTypeInfo<Map>());
oxReturnError(io->field("pairs", &obj->m_pairs));
return {};
}
}

View File

@@ -26,7 +26,7 @@
namespace ox {
#if defined(OX_USE_STDLIB) && __has_include(<unistd.h>)
[[nodiscard]]
[[nodiscard]] [[maybe_unused]]
static auto symbolicate([[maybe_unused]]void **frames,
[[maybe_unused]]std::size_t frameCnt,
[[maybe_unused]]const char *linePrefix) {

View File

@@ -16,6 +16,7 @@
#include "istring.hpp"
#include "byteswap.hpp"
#include "concepts.hpp"
#include "conv.hpp"
#include "cstringview.hpp"
#include "cstrops.hpp"
#include "def.hpp"

View File

@@ -13,6 +13,7 @@ namespace ox {
template class BasicString<8>;
static_assert(StringView("Write") != String(""));
static_assert(ox::strcmp(String{}.c_str(), "\0") == 0);
static_assert(String("Write") != StringView(""));
static_assert(String("Write") == StringView("Write"));
static_assert(String(StringView("Write")) == StringView("Write"));

View File

@@ -193,7 +193,9 @@ class BasicString {
constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept;
constexpr void resize(size_t sz) noexcept {
++sz;
m_buff.resize(sz);
m_buff[sz - 1] = 0;
}
[[nodiscard]]
@@ -248,38 +250,19 @@ class BasicString {
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString() noexcept {
if (!m_buff.empty()) {
m_buff[0] = 0;
} else {
m_buff.push_back(0);
}
m_buff.resize(1);
}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept: m_buff(cap + 1) {
// GCC complains if you don't do this pretty unnecessary size check
if (!m_buff.empty()) {
m_buff[0] = 0;
}
}
constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept: m_buff(cap + 1) {}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str) noexcept {
if (!m_buff.empty()) {
m_buff[0] = 0;
} else {
m_buff.push_back(0);
}
set(str);
}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(const char8_t *str) noexcept {
if (!m_buff.empty()) {
m_buff[0] = 0;
} else {
m_buff.push_back(0);
}
set(str);
}
@@ -287,21 +270,15 @@ template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str, std::size_t size) noexcept {
m_buff.resize(size + 1);
ox::listcpy(m_buff.data(), str, size);
m_buff[size] = 0;
}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(StringLiteral const&str) noexcept:
BasicString(StringView{str.data(), str.bytes()}) {
BasicString(StringView{str.data(), str.len()}) {
}
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(CRStringView str) noexcept {
if (m_buff.empty()) {
m_buff.push_back(0);
} else {
m_buff[0] = 0;
}
set(str);
}
@@ -312,6 +289,8 @@ constexpr BasicString<SmallStringSize_v>::BasicString(const BasicString &other)
template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v>::BasicString(BasicString &&other) noexcept: m_buff(std::move(other.m_buff)) {
other.m_buff.resize(1);
other.m_buff[0] = 0;
}
template<std::size_t SmallStringSize_v>
@@ -357,6 +336,8 @@ template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(BasicString &&src) noexcept {
if (this != &src) {
m_buff = std::move(src.m_buff);
src.m_buff.resize(1);
src.m_buff[0] = 0;
}
return *this;
}

View File

@@ -18,12 +18,12 @@
#include <ox/std/std.hpp>
[[nodiscard]]
static uint64_t nowMs() {
static uint64_t steadyNowMs() {
#if __has_include(<chrono>)
using namespace std::chrono;
return static_cast<uint64_t>(
duration_cast<milliseconds>(
system_clock::now().time_since_epoch()).count());
steady_clock::now().time_since_epoch()).count());
#else
return 0;
#endif
@@ -41,13 +41,13 @@ uint64_t timeMapStrToUuid(int elemCnt, int lookups, uint64_t seed = 4321) noexce
auto const keys = map.keys();
ox::Random rand;
// start
auto const startTime = nowMs();
auto const startTime = steadyNowMs();
for (int i = 0; i < lookups; ++i) {
auto const&k = keys[rand.gen() % keys.size()];
map[k];
oxExpect(map[k], ox::UUID::fromString(k).unwrap());
}
return nowMs() - startTime;
return steadyNowMs() - startTime;
}
template<typename Map = ox::SmallMap<ox::UUID, ox::String>>
@@ -62,16 +62,16 @@ uint64_t timeMapUuidToStr(int elemCnt, int lookups, uint64_t seed = 4321) noexce
auto const keys = map.keys();
ox::Random rand;
// start
auto const startTime = nowMs();
auto const startTime = steadyNowMs();
for (int i = 0; i < lookups; ++i) {
auto const&k = keys[rand.gen() % keys.size()];
oxExpect(map[k], k.toString());
}
return nowMs() - startTime;
return steadyNowMs() - startTime;
}
static ox::Error compareMaps(int lookupCnt = 1'000'000) {
auto const seed = nowMs();
auto const seed = steadyNowMs();
uint64_t hashTime{};
uint64_t smallTime{};
int elemCnt = 1;

View File

@@ -185,6 +185,8 @@ struct enable_if<true, T> {
using type = T;
};
template<bool B, typename T>
using enable_if_t = typename enable_if<B, T>::type;
template<typename T>
struct is_pointer {

View File

@@ -23,17 +23,16 @@
namespace ox {
template<typename T>
struct Vec {
class Vec2 {
public:
using value_type = T;
using value_type = float;
using size_type = std::size_t;
static constexpr auto TypeName = "net.drinkingtea.ox.Point";
static constexpr auto TypeVersion = 1;
T x = 0;
T y = 0;
float x = 0;
float y = 0;
template<typename RefType = value_type&, typename PtrType = value_type*, bool reverse = false>
struct iterator: public ox::Iterator<std::bidirectional_iterator_tag, value_type> {
@@ -141,14 +140,14 @@ struct Vec {
};
constexpr Vec() noexcept = default;
constexpr Vec2() noexcept = default;
template<typename ...Args>
constexpr Vec(T pX, T pY) noexcept: x(pX), y(pY) {
constexpr Vec2(float pX, float pY) noexcept: x(pX), y(pY) {
}
#if __has_include(<imgui.h>)
explicit constexpr Vec(const ImVec2 &v) noexcept: Vec(v.x, v.y) {
explicit constexpr Vec2(const ImVec2 &v) noexcept: Vec2(v.x, v.y) {
}
explicit inline operator ImVec2() const noexcept {
@@ -228,7 +227,7 @@ struct Vec {
}
}
constexpr auto operator==(const Vec &v) const noexcept {
constexpr auto operator==(const Vec2 &v) const noexcept {
for (auto i = 0u; i < v.size(); ++i) {
if ((*this)[i] != v[i]) {
return false;
@@ -237,29 +236,71 @@ struct Vec {
return true;
}
constexpr auto operator!=(const Vec &v) const noexcept {
constexpr auto operator!=(const Vec2 &v) const noexcept {
return !operator==(v);
}
explicit constexpr operator class Point() const noexcept;
explicit constexpr operator class Size() const noexcept;
[[nodiscard]]
constexpr std::size_t size() const noexcept {
return 2;
}
constexpr Vec2 operator+(float i) const noexcept {
return {x + i, y + i};
}
constexpr Vec2 operator+=(float i) noexcept {
x += i;
y += i;
return *this;
}
constexpr Vec2 operator-(float i) const noexcept {
return {x - i, y - i};
}
constexpr Vec2 operator-=(float i) noexcept {
x -= i;
y -= i;
return *this;
}
constexpr Vec2 operator*(float i) const noexcept {
return {x * i, y * i};
}
constexpr Vec2 operator*=(float i) noexcept {
x *= i;
y *= i;
return *this;
}
constexpr Vec2 operator/(float i) const noexcept {
return {x / i, y / i};
}
constexpr Vec2 operator/=(float i) noexcept {
x /= i;
y /= i;
return *this;
}
protected:
[[nodiscard]]
constexpr T *start() noexcept {
return &x;
constexpr float *start() noexcept {
return&x;
}
[[nodiscard]]
constexpr const T *start() const noexcept {
constexpr const float *start() const noexcept {
return &x;
}
};
using Vec2 = Vec<float>;
template<typename T>
constexpr Error model(T *io, ox::CommonPtrWith<Vec2> auto *obj) noexcept {
oxReturnError(io->template setTypeInfo<Vec2>());

View File

@@ -271,7 +271,7 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
constexpr bool contains(MaybeView_t<T> const&) const noexcept;
constexpr iterator<T&, T*, false> insert(
std::size_t pos, std::size_t cnt, T val) noexcept(useNoexcept);
std::size_t pos, std::size_t cnt, T const&val) noexcept(useNoexcept);
constexpr iterator<T&, T*, false> insert(std::size_t pos, T val) noexcept(useNoexcept);
@@ -531,29 +531,23 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeView_t<T> co
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
Vector<T, SmallVectorSize, Allocator>::insert(
std::size_t pos, std::size_t cnt, T val) noexcept(useNoexcept) {
std::size_t pos, std::size_t cnt, T const&val) noexcept(useNoexcept) {
if (m_size + cnt > m_cap) {
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
if (pos < m_size) {
m_items[pos] = std::move(val);
} else {
for (auto i = 0u; i < cnt; ++i) {
std::construct_at(&m_items[pos + i], m_items[pos]);
}
}
if (pos < m_size) {
for (auto i = m_size + cnt - 1; i > pos; --i) {
std::construct_at(&m_items[i], std::move(m_items[i - cnt]));
}
for (auto i = pos; i < pos + cnt; ++i) {
m_items[i] = val;
}
} else {
if (pos < m_size) {
for (auto i = m_size + cnt - 1; i > pos; --i) {
std::construct_at(&m_items[i], std::move(m_items[i - cnt]));
}
m_items[pos] = std::move(val);
} else {
for (auto i = 0u; i < cnt; ++i) {
std::construct_at(&m_items[pos + i], m_items[pos]);
}
for (auto i = 0u; i < cnt; ++i) {
std::construct_at(&m_items[pos + i], m_items[pos]);
}
}
++m_size;
m_size += cnt;
return begin() + pos;
}
@@ -562,20 +556,14 @@ constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&,
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, T val) noexcept(useNoexcept) {
if (m_size == m_cap) {
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
if (pos < m_size) {
m_items[pos] = std::move(val);
} else {
std::construct_at(&m_items[pos], m_items[pos]);
}
if (pos < m_size) {
for (auto i = m_size; i > pos; --i) {
std::construct_at(&m_items[i], std::move(m_items[i - 1]));
}
m_items[pos] = std::move(val);
} else {
if (pos < m_size) {
for (auto i = m_size; i > pos; --i) {
std::construct_at(&m_items[i], std::move(m_items[i - 1]));
}
m_items[pos] = std::move(val);
} else {
std::construct_at(&m_items[pos], m_items[pos]);
}
std::construct_at(&m_items[pos], std::move(val));
}
++m_size;
return begin() + pos;