diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-27 07:29:42 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-27 12:37:20 +0100 |
commit | f60c3734e38408b97e10e29a6c1d8780770d5b79 (patch) | |
tree | 20f778f31725b8960d13a04388757b2f53fa0164 /serialize | |
parent | 48b8e559cd72c95a5f72de625a608e85026e3785 (diff) |
compat/prelude: add operator""_uz() for size_t
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/binary-reader.inl | 6 | ||||
-rw-r--r-- | serialize/binary-writer.inl | 4 | ||||
-rw-r--r-- | serialize/magnum-vector.hpp | 4 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 8 | ||||
-rw-r--r-- | serialize/world-writer.cpp | 8 |
5 files changed, 15 insertions, 15 deletions
diff --git a/serialize/binary-reader.inl b/serialize/binary-reader.inl index 7b831f30..1234b08a 100644 --- a/serialize/binary-reader.inl +++ b/serialize/binary-reader.inl @@ -23,7 +23,7 @@ constexpr T binary_reader<It>::read() noexcept(false) fm_soft_assert((std::ptrdiff_t)N <= std::distance(it, end)); num_bytes_read += N; char buf[N]; - for (std::size_t i = 0; i < N; i++) + for (auto i = 0_uz; i < N; i++) buf[i] = *it++; return maybe_byteswap(std::bit_cast<T, decltype(buf)>(buf)); } @@ -37,7 +37,7 @@ constexpr std::array<char, N> binary_reader<It>::read() noexcept(false) array = {}; fm_soft_assert(N <= (std::size_t)std::distance(it, end)); num_bytes_read += N; - for (std::size_t i = 0; i < N; i++) + for (auto i = 0_uz; i < N; i++) array[i] = *it++; return array; } @@ -74,7 +74,7 @@ constexpr auto binary_reader<It>::read_asciiz_string() noexcept(false) }; fixed_string ret; - for (std::size_t i = 0; i < MAX && it != end; i++) + for (auto i = 0_uz; i < MAX && it != end; i++) { const char c = *it++; ret.buf[i] = c; diff --git a/serialize/binary-writer.inl b/serialize/binary-writer.inl index e5a7ba16..a847903d 100644 --- a/serialize/binary-writer.inl +++ b/serialize/binary-writer.inl @@ -17,7 +17,7 @@ constexpr void binary_writer<It>::write(T x) noexcept _bytes_written += sizeof(T); constexpr std::size_t N = sizeof(T); const auto buf = std::bit_cast<std::array<char, N>, T>(maybe_byteswap(x)); - for (std::size_t i = 0; i < N; i++) + for (auto i = 0_uz; i < N; i++) *it++ = buf[i]; } @@ -34,7 +34,7 @@ constexpr void binary_writer<It>::write_asciiz_string(StringView str) noexcept fm_debug_assert(str.flags() & StringViewFlag::NullTerminated); const auto sz = str.size(); _bytes_written += sz + 1; - for (std::size_t i = 0; i < sz; i++) + for (auto i = 0_uz; i < sz; i++) *it++ = str[i]; *it++ = '\0'; } diff --git a/serialize/magnum-vector.hpp b/serialize/magnum-vector.hpp index 08997b90..b8383d96 100644 --- a/serialize/magnum-vector.hpp +++ b/serialize/magnum-vector.hpp @@ -16,7 +16,7 @@ template <std::size_t N, typename T> void adl_serializer<Magnum::Math::Vector<N, T>>::to_json(json& j, const vec& val) { std::array<T, N> array{}; - for (std::size_t i = 0; i < N; i++) + for (auto i = 0_uz; i < N; i++) array[i] = val[i]; using nlohmann::to_json; to_json(j, array); @@ -28,7 +28,7 @@ void adl_serializer<Magnum::Math::Vector<N, T>>::from_json(const json& j, vec& v std::array<T, N> array{}; using nlohmann::from_json; from_json(j, array); - for (std::size_t i = 0; i < N; i++) + for (auto i = 0_uz; i < N; i++) val[i] = array[i]; } diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 4f31b88b..3060579f 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -73,14 +73,14 @@ void reader_state::read_sceneries(reader_t& s) fm_soft_assert(sz < scenery_id_max); sceneries.resize(sz); - std::size_t i = 0; + auto i = 0_uz; while (i < sz) { std::uint8_t num; num << s; fm_soft_assert(num > 0); auto str = s.read_asciiz_string<atlas_name_max>(); const auto sc_ = loader.scenery(str); - for (std::size_t n = 0; n < num; n++) + for (auto n = 0_uz; n < num; n++) { atlasid id; id << s; fm_soft_assert(id < sz); @@ -120,7 +120,7 @@ void reader_state::read_chunks(reader_t& s) { const auto N = s.read<chunksiz>(); - for (std::size_t k = 0; k < N; k++) + for (auto k = 0_uz; k < N; k++) { std::decay_t<decltype(chunk_magic)> magic; magic << s; @@ -130,7 +130,7 @@ void reader_state::read_chunks(reader_t& s) coord.x << s; coord.y << s; auto& chunk = (*_world)[coord]; - for (std::size_t i = 0; i < TILE_COUNT; i++) + for (auto i = 0_uz; i < TILE_COUNT; i++) { const tilemeta flags = s.read<tilemeta>(); tile_ref t = chunk[i]; diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index 6bb033ab..2a58a51b 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -256,7 +256,7 @@ void writer_state::serialize_scenery() s << (atlasid)sz; StringView last; - for (std::size_t i = 0; i < sz; i++) + for (auto i = 0_uz; i < sz; i++) { fm_debug_assert(s.bytes_written() + atlasbuf_size1 < atlasbuf_size); const auto& [sc, idx] = vec[i]; @@ -264,8 +264,8 @@ void writer_state::serialize_scenery() { fm_assert(sc->name.size() < atlas_name_max); last = sc->name; - std::size_t num = 1; - for (std::size_t j = i+1; j < sz && vec[j].s->name == sc->name; j++) + auto num = 1_uz; + for (auto j = i+1; j < sz && vec[j].s->name == sc->name; j++) num++; fm_assert(num < int_max<std::uint8_t>); s << (std::uint8_t)num; @@ -292,7 +292,7 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords coord) s << chunk_magic << coord.x << coord.y; - for (std::size_t i = 0; i < TILE_COUNT; i++) + for (auto i = 0_uz; i < TILE_COUNT; i++) { const tile_proto x = c[i]; const auto ground = x.ground(), wall_north = x.wall_north(), wall_west = x.wall_west(); |