| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,10 +120,10 @@ template<class T> struct DynamicArrayOf final { | |||
| 120 | 120 | [[nodiscard]] auto move() -> MoveSlice { return MoveSlice{amendBegin(), m_count}; } | |
| 121 | 121 | ||
| 122 | 122 | void ensureCapacity(Count count) { | |
| 123 | - if (totalCapacity() < count) growBy(count - totalCapacity()); | ||
| 123 | + if (totalCapacity() < count) growBy(static_cast<size_t>(count - totalCapacity())); | ||
| 124 | 124 | } | |
| 125 | 125 | void ensureUnusedCapacity(Count count) { | |
| 126 | - if (unusedCapacity() < count) growBy(count - unusedCapacity()); | ||
| 126 | + if (unusedCapacity() < count) growBy(static_cast<size_t>(count - unusedCapacity())); | ||
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | 129 | void clear() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,11 +8,9 @@ namespace array19 { | |||
| 8 | 8 | template<class T> constexpr bool operator==(const SliceOf<T>& a, const SliceOf<T>& b) { | |
| 9 | 9 | if (a.count() != b.count()) return false; | |
| 10 | 10 | for (size_t i = 0u; i < a.count() && i < b.count(); i++) { | |
| 11 | - if (!(a[i] == b[i])) return false; | ||
| 11 | + if (a[i] != b[i]) return false; | ||
| 12 | 12 | } | |
| 13 | 13 | return true; | |
| 14 | 14 | } | |
| 15 | 15 | ||
| 16 | - template<class T> constexpr bool operator!=(const SliceOf<T>& a, const SliceOf<T>& b) { return !(a == b); } | ||
| 17 | - | ||
| 18 | 16 | } // namespace array19 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,13 +28,13 @@ template<class C> struct WithIndex { | |||
| 28 | 28 | constexpr auto operator++() -> iterator& { return (++it, ++index, *this); } | |
| 29 | 29 | }; | |
| 30 | 30 | ||
| 31 | - constexpr WithIndex(C& c) noexcept : c(c) {} | ||
| 31 | + constexpr WithIndex(C& c) noexcept : c(&c) {} | ||
| 32 | 32 | ||
| 33 | - [[nodiscard]] constexpr auto begin() -> iterator { return iterator{adlBegin(c), {}}; } | ||
| 34 | - [[nodiscard]] constexpr auto end() -> It { return adlEnd(c); } | ||
| 33 | + [[nodiscard]] constexpr auto begin() -> iterator { return iterator{adlBegin(*c), {}}; } | ||
| 34 | + [[nodiscard]] constexpr auto end() -> It { return adlEnd(*c); } | ||
| 35 | 35 | ||
| 36 | 36 | private: | |
| 37 | - C& c; | ||
| 37 | + C* c; | ||
| 38 | 38 | }; | |
| 39 | 39 | ||
| 40 | 40 | template<class C> WithIndex(C&) -> WithIndex<C>; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ using namespace array19; | |||
| 5 | 5 | void constexpr_WithIndex_test() { | |
| 6 | 6 | constexpr auto sum = [] { | |
| 7 | 7 | int a[] = {1, 2, 3}; | |
| 8 | - auto r = 0; | ||
| 8 | + auto r = size_t{}; | ||
| 9 | 9 | #ifdef _MSC_VER | |
| 10 | 10 | auto wi = WithIndex{a}; // cl crashes if we inline this && run it as constexpr | |
| 11 | 11 | for (auto [v, i] : wi) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,7 +89,7 @@ constexpr auto buildMetaEnumFor( | |||
| 89 | 89 | index++, | |
| 90 | 90 | memberNames[nameIndex++], | |
| 91 | 91 | ((value = members.filled ? members.value : nextValue), | |
| 92 | - nextValue = value + 1, | ||
| 92 | + nextValue = static_cast<Underlying>(value + 1), | ||
| 93 | 93 | static_cast<Enum>(value)) // | |
| 94 | 94 | }...} // | |
| 95 | 95 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ constexpr bool isCppIdentifierChar(char c) { | |||
| 16 | 16 | ||
| 17 | 17 | template<size_t N> constexpr auto extractEnumMemberNames(StringView body) -> Array<StringView, N> { | |
| 18 | 18 | auto result = Array<StringView, N>{}; | |
| 19 | - auto i = 0; | ||
| 19 | + auto i = 0u; | ||
| 20 | 20 | auto p = body.data; | |
| 21 | 21 | auto e = body.data + body.count; | |
| 22 | 22 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,10 +57,10 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf { | |||
| 57 | 57 | [[nodiscard]] operator Slice() const noexcept { return Slice{begin(), m_count}; } | |
| 58 | 58 | ||
| 59 | 59 | void ensureCapacity(Count count) { | |
| 60 | - if (totalCapacity() < count) growBy(count - totalCapacity()); | ||
| 60 | + if (totalCapacity() < count) growBy(static_cast<size_t>(count - totalCapacity())); | ||
| 61 | 61 | } | |
| 62 | 62 | void ensureUnusedCapacity(Count count) { | |
| 63 | - if (unusedCapacity() < count) growBy(count); | ||
| 63 | + if (unusedCapacity() < count) growBy(static_cast<size_t>(count - unusedCapacity())); | ||
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | 66 | /// inserts a single value to the set if it is not yet present | |
@@ -90,7 +90,7 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf { | |||
| 90 | 90 | return true; | |
| 91 | 91 | } | |
| 92 | 92 | if (it != end()) { | |
| 93 | - memmove(it + 1, it, end() - it); | ||
| 93 | + memmove(it + 1, it, static_cast<size_t>(end() - it)); | ||
| 94 | 94 | } | |
| 95 | 95 | *it = v; | |
| 96 | 96 | m_count++; | |
@@ -103,7 +103,7 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf { | |||
| 103 | 103 | void remove(ConstIterator cIt) { | |
| 104 | 104 | auto it = const_cast<Iterator>(cIt); | |
| 105 | 105 | if (it + 1 != end()) { | |
| 106 | - memmove(it, it + 1, end() - it - 1); | ||
| 106 | + memmove(it, it + 1, static_cast<size_t>(end() - it - 1)); | ||
| 107 | 107 | } | |
| 108 | 108 | m_count--; | |
| 109 | 109 | } | |
@@ -210,15 +210,15 @@ template<class T, class Less = DefaultLess> struct OrderedSetOf { | |||
| 210 | 210 | } | |
| 211 | 211 | ||
| 212 | 212 | private: | |
| 213 | - [[nodiscard]] auto grownStorage(int growBy) const -> AmendableSlice { | ||
| 213 | + [[nodiscard]] auto grownStorage(size_t growBy) const -> AmendableSlice { | ||
| 214 | 214 | auto cur = m_capacity; | |
| 215 | 215 | auto res = (cur << 1) - (cur >> 1) + (cur >> 4); // * 1.563 | |
| 216 | 216 | if (res < 5) res = 5; | |
| 217 | 217 | if (res < m_capacity + growBy) res = m_capacity + growBy; | |
| 218 | 218 | auto ptr = Utils::allocate(res); | |
| 219 | 219 | return AmendableSlice{ptr, res}; | |
| 220 | 220 | } | |
| 221 | - void growBy(int by) { | ||
| 221 | + void growBy(size_t by) { | ||
| 222 | 222 | auto newStorage = grownStorage(by); | |
| 223 | 223 | memcpy(newStorage.begin(), m_pointer, m_count); | |
| 224 | 224 | Utils::deallocate(SliceOf{m_pointer, m_capacity}); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ struct Person { | |||
| 19 | 19 | template<class A> void serialize(A& a, std::string& s) { | |
| 20 | 20 | auto size = s.size(); | |
| 21 | 21 | serialize(a, size); | |
| 22 | - if (a.mode == ArchiveMode::Read) { | ||
| 22 | + if constexpr (A::mode == ArchiveMode::Read) { | ||
| 23 | 23 | s.resize(size); | |
| 24 | 24 | for (auto i = 0U; i < size; i++) serialize(a, s[i]); | |
| 25 | 25 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ template<class T> auto endianFlipFor(T input) -> T { | |||
| 18 | 18 | return input; | |
| 19 | 19 | else if constexpr (N == 2) { | |
| 20 | 20 | auto value = *(uint16_t*)&input; | |
| 21 | - value = (uint16_t)(value << 8) | (value >> 8); | ||
| 21 | + value = static_cast<uint16_t>((value << 8) | (value >> 8)); | ||
| 22 | 22 | return *(T*)&value; | |
| 23 | 23 | } | |
| 24 | 24 | else if constexpr (N == 4) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | namespace serialize19 { | |
| 8 | 8 | ||
| 9 | 9 | template<Archive A, size_t size> void serialize(A& a, std::bitset<size>& bitset) { | |
| 10 | - if (a.mode == ArchiveMode::Read) { | ||
| 10 | + if constexpr (A::mode == ArchiveMode::Read) { | ||
| 11 | 11 | for (auto i = 0u; i < size;) { | |
| 12 | 12 | auto chunk = uint8_t{}; | |
| 13 | 13 | serialize(a, chunk); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments