diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-03-12 00:37:23 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-03-12 22:32:38 +0100 |
commit | cbade33906dc0d090d5dba6231fb48e359afff95 (patch) | |
tree | 391399754e43332fa7bde336255dd17d83683228 /asl | |
parent | c8b73031d8a9f7770410c9d0e6da5b230e501e85 (diff) |
Some more shit
Diffstat (limited to 'asl')
-rw-r--r-- | asl/base/config.hpp | 5 | ||||
-rw-r--r-- | asl/base/defer.hpp | 4 | ||||
-rw-r--r-- | asl/base/utility.hpp | 9 | ||||
-rw-r--r-- | asl/containers/buffer.hpp | 28 | ||||
-rw-r--r-- | asl/containers/hash_set.hpp | 4 | ||||
-rw-r--r-- | asl/containers/intrusive_list.hpp | 2 | ||||
-rw-r--r-- | asl/formatting/format.hpp | 8 | ||||
-rw-r--r-- | asl/logging/logging.hpp | 2 | ||||
-rw-r--r-- | asl/memory/memory.hpp | 2 | ||||
-rw-r--r-- | asl/strings/string_builder.hpp | 5 | ||||
-rw-r--r-- | asl/strings/string_view.hpp | 30 | ||||
-rw-r--r-- | asl/types/span.hpp | 30 | ||||
-rw-r--r-- | asl/types/status.hpp | 16 | ||||
-rw-r--r-- | asl/types/status_or.hpp | 10 |
14 files changed, 81 insertions, 74 deletions
diff --git a/asl/base/config.hpp b/asl/base/config.hpp index a8652c5..f5756c3 100644 --- a/asl/base/config.hpp +++ b/asl/base/config.hpp @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: BSD-3-Clause +// NOLINTBEGIN(*-macro-to-enum) + #pragma once #if defined(_WIN32) @@ -19,3 +21,6 @@ #else #error Unknown compiler #endif + +// NOLINTEND(*-macro-to-enum) + diff --git a/asl/base/defer.hpp b/asl/base/defer.hpp index c9c08ba..a932758 100644 --- a/asl/base/defer.hpp +++ b/asl/base/defer.hpp @@ -18,7 +18,9 @@ class DeferCallback public: template<typename T> - explicit DeferCallback(T&& callback) : m_callback(std::forward<T>(callback)) + explicit DeferCallback(T&& callback) + requires (!same_as<un_cvref_t<T>, DeferCallback>) + : m_callback(std::forward<T>(callback)) { } diff --git a/asl/base/utility.hpp b/asl/base/utility.hpp index 07f8b51..206a5b1 100644 --- a/asl/base/utility.hpp +++ b/asl/base/utility.hpp @@ -11,25 +11,25 @@ namespace std { template<typename T> -constexpr asl::un_ref_t<T>&& move(T&& t) noexcept // NOLINT +[[nodiscard]] constexpr asl::un_ref_t<T>&& move(T&& t) noexcept // NOLINT { return static_cast<asl::un_ref_t<T>&&>(t); } template<typename T> -constexpr T&& forward(asl::un_ref_t<T>& t) noexcept // NOLINT +[[nodiscard]] constexpr T&& forward(asl::un_ref_t<T>& t) noexcept // NOLINT { return static_cast<T&&>(t); } template< class T > -constexpr T&& forward(asl::un_ref_t<T>&& t) noexcept // NOLINT +[[nodiscard]] constexpr T&& forward(asl::un_ref_t<T>&& t) noexcept // NOLINT { return static_cast<T&&>(t); } template<typename T, typename U> -constexpr auto forward_like(U&& x) noexcept -> asl::copy_cref_t<T, U> // NOLINT +[[nodiscard]] constexpr auto forward_like(U&& x) noexcept -> asl::copy_cref_t<T, U> // NOLINT { using return_type = asl::copy_cref_t<T, U&&>; return static_cast<return_type>(x); @@ -37,7 +37,6 @@ constexpr auto forward_like(U&& x) noexcept -> asl::copy_cref_t<T, U> // NOLINT } // namespace std - namespace asl { diff --git a/asl/containers/buffer.hpp b/asl/containers/buffer.hpp index c7fc01f..0cad78f 100644 --- a/asl/containers/buffer.hpp +++ b/asl/containers/buffer.hpp @@ -46,7 +46,7 @@ private: static_assert(align_of<T*> == align_of<isize_t>); static_assert(align_of<T*> == align_of<size_t>); - constexpr size_t load_size_encoded() const + [[nodiscard]] constexpr size_t load_size_encoded() const { size_t s{}; asl::memcpy(&s, &m_size_encoded_, sizeof(size_t)); @@ -84,21 +84,21 @@ private: } } - constexpr bool is_on_heap() const + [[nodiscard]] constexpr bool is_on_heap() const { return is_on_heap(load_size_encoded()); } constexpr T* push_uninit() { - isize_t sz = size(); + const isize_t sz = size(); resize_uninit_inner(sz + 1); return data() + sz; } constexpr void resize_uninit_inner(isize_t new_size) { - isize_t old_size = size(); + const isize_t old_size = size(); if (!trivially_destructible<T> && new_size < old_size) { destroy_n(data() + new_size, old_size - new_size); @@ -110,7 +110,7 @@ private: constexpr void set_size_inline(isize_t new_size) { ASL_ASSERT(new_size >= 0 && new_size <= kInlineCapacity); - size_t size_encoded = (load_size_encoded() & size_t{0x00ff'ffff'ffff'ffff}) | (bit_cast<size_t>(new_size) << 56U); + const size_t size_encoded = (load_size_encoded() & size_t{0x00ff'ffff'ffff'ffff}) | (bit_cast<size_t>(new_size) << 56U); store_size_encoded(size_encoded); } @@ -144,8 +144,8 @@ private: } else if (!assign || m_allocator == other.m_allocator) { - isize_t other_n = other.size(); - isize_t this_n = size(); + const isize_t other_n = other.size(); + const isize_t this_n = size(); resize_uninit_inner(other_n); if (other_n <= this_n) { @@ -160,7 +160,7 @@ private: else { destroy(); - isize_t n = other.size(); + const isize_t n = other.size(); ASL_ASSERT(n <= kInlineCapacity); relocate_uninit_n(data(), other.data(), n); set_size_inline(n); @@ -176,8 +176,8 @@ private: void copy_range(span<const T> to_copy) { - isize_t this_size = size(); - isize_t new_size = to_copy.size(); + const isize_t this_size = size(); + const isize_t new_size = to_copy.size(); resize_uninit_inner(to_copy.size()); ASL_ASSERT(capacity() >= new_size); @@ -268,12 +268,12 @@ public: destroy(); } - constexpr isize_t size() const + [[nodiscard]] constexpr isize_t size() const { return decode_size(load_size_encoded()); } - constexpr isize_t capacity() const + [[nodiscard]] constexpr isize_t capacity() const { if constexpr (kInlineCapacity == 0) { @@ -287,7 +287,7 @@ public: void clear() { - isize_t current_size = size(); + const isize_t current_size = size(); if (current_size == 0) { return; } destroy_n(data(), current_size); @@ -357,7 +357,7 @@ public: constexpr void resize_zero(isize_t new_size) requires trivially_default_constructible<T> && trivially_destructible<T> { - isize_t old_size = size(); + const isize_t old_size = size(); resize_uninit(new_size); if (new_size > old_size) diff --git a/asl/containers/hash_set.hpp b/asl/containers/hash_set.hpp index 02a8036..5422d5e 100644 --- a/asl/containers/hash_set.hpp +++ b/asl/containers/hash_set.hpp @@ -72,7 +72,7 @@ protected: ASL_NO_UNIQUE_ADDRESS Allocator m_allocator; - constexpr isize_t max_size() const + [[nodiscard]] constexpr isize_t max_size() const { // Max load factor is 75% return (m_capacity >> 1) + (m_capacity >> 2); // NOLINT(*-signed-bitwise) @@ -384,7 +384,7 @@ public: } } - constexpr isize_t size() const { return m_size; } + [[nodiscard]] constexpr isize_t size() const { return m_size; } template<typename... Args> void insert(Args&&... args) diff --git a/asl/containers/intrusive_list.hpp b/asl/containers/intrusive_list.hpp index af11424..8cafdff 100644 --- a/asl/containers/intrusive_list.hpp +++ b/asl/containers/intrusive_list.hpp @@ -47,7 +47,7 @@ public: ASL_DEFAULT_MOVE(IntrusiveList); ~IntrusiveList() = default; - constexpr bool is_empty() const { return m_head == nullptr; } + [[nodiscard]] constexpr bool is_empty() const { return m_head == nullptr; } void push_front(T* node) { diff --git a/asl/formatting/format.hpp b/asl/formatting/format.hpp index c3a1f94..9323a57 100644 --- a/asl/formatting/format.hpp +++ b/asl/formatting/format.hpp @@ -32,7 +32,7 @@ struct type_erased_arg template<formattable T> static constexpr void erased_fn(Formatter& f, const void* data) { - AslFormat(f, *reinterpret_cast<const T*>(data)); + AslFormat(f, *static_cast<const T*>(data)); } template<formattable T> @@ -44,7 +44,7 @@ struct type_erased_arg void format(Writer*, string_view fmt, span<const type_erased_arg> args); -} // namespace internals +} // namespace format_internals class Formatter { @@ -60,7 +60,7 @@ public: m_writer->write(as_bytes(s.as_span())); } - constexpr Writer* writer() const { return m_writer; } + [[nodiscard]] constexpr Writer* writer() const { return m_writer; } }; template<formattable... Args> @@ -68,7 +68,7 @@ void format(Writer* w, string_view fmt, const Args&... args) { if constexpr (types_count<Args...> > 0) { - format_internals::type_erased_arg type_erased_args[] = { + const format_internals::type_erased_arg type_erased_args[] = { format_internals::type_erased_arg(args)... }; diff --git a/asl/logging/logging.hpp b/asl/logging/logging.hpp index 9c74b31..9774927 100644 --- a/asl/logging/logging.hpp +++ b/asl/logging/logging.hpp @@ -78,7 +78,7 @@ void log(level l, const source_location& sl, string_view fmt, const Args&... arg } else { - format_internals::type_erased_arg type_erased_args[] = { + const format_internals::type_erased_arg type_erased_args[] = { format_internals::type_erased_arg(args)... }; log_inner(l, fmt, type_erased_args, sl); diff --git a/asl/memory/memory.hpp b/asl/memory/memory.hpp index 96ab562..2c5301e 100644 --- a/asl/memory/memory.hpp +++ b/asl/memory/memory.hpp @@ -9,7 +9,7 @@ #include "asl/base/utility.hpp" #include "asl/memory/layout.hpp" -constexpr void* operator new(size_t, void* ptr) +constexpr void* operator new(size_t, void* ptr) noexcept { return ptr; } diff --git a/asl/strings/string_builder.hpp b/asl/strings/string_builder.hpp index eed9e6a..d15f100 100644 --- a/asl/strings/string_builder.hpp +++ b/asl/strings/string_builder.hpp @@ -30,7 +30,7 @@ public: constexpr StringBuilder& operator=(const StringBuilder&) requires copy_assignable<Allocator> = default; constexpr StringBuilder& operator=(StringBuilder&&) = default; - constexpr string_view as_string_view() const + [[nodiscard]] constexpr string_view as_string_view() const { auto span = m_buffer.as_span(); return string_view{span.data(), span.size()}; @@ -98,10 +98,11 @@ public: void write(span<const byte> str) override { + // NOLINTNEXTLINE(*-reinterpret-cast) m_builder.push(string_view{reinterpret_cast<const char*>(str.data()), str.size()}); } - constexpr string_view as_string_view() const + [[nodiscard]] constexpr string_view as_string_view() const { return m_builder.as_string_view(); } diff --git a/asl/strings/string_view.hpp b/asl/strings/string_view.hpp index a3481f8..27d20ec 100644 --- a/asl/strings/string_view.hpp +++ b/asl/strings/string_view.hpp @@ -20,7 +20,7 @@ class string_view public: constexpr string_view() = default; - constexpr string_view(nullptr_t) : string_view() {} // NOLINT(*-explicit-conversions) + constexpr string_view(nullptr_t) : string_view() {} // NOLINT(*explicit*) constexpr string_view(const char* data, isize_t size) : m_data{data} @@ -28,9 +28,9 @@ public: {} template<isize_t kSize> - constexpr string_view(const char (&str)[kSize]) // NOLINT(*-explicit-conversions) + constexpr string_view(const char (&str)[kSize]) // NOLINT(*explicit*) requires (kSize >= 1) - : m_data{str} + : m_data{static_cast<const char*>(str)} , m_size{kSize - 1} { ASL_ASSERT(m_data[kSize - 1] == '\0'); // NOLINT(*-pointer-arithmetic) @@ -38,7 +38,7 @@ public: static constexpr string_view from_zstr(const char* str) { - return string_view(str, asl::strlen(str)); + return {str, asl::strlen(str)}; } constexpr string_view(const string_view&) = default; @@ -49,18 +49,18 @@ public: ~string_view() = default; - constexpr isize_t size() const { return m_size; } + [[nodiscard]] constexpr isize_t size() const { return m_size; } - constexpr bool is_empty() const { return m_size == 0; } + [[nodiscard]] constexpr bool is_empty() const { return m_size == 0; } - constexpr const char* data() const { return m_data; } + [[nodiscard]] constexpr const char* data() const { return m_data; } - constexpr contiguous_iterator<const char> begin() const { return contiguous_iterator{m_data}; } + [[nodiscard]] constexpr contiguous_iterator<const char> begin() const { return contiguous_iterator{m_data}; } // NOLINTNEXTLINE(*-pointer-arithmetic) - constexpr contiguous_iterator<const char> end() const { return contiguous_iterator{m_data + m_size}; } + [[nodiscard]] constexpr contiguous_iterator<const char> end() const { return contiguous_iterator{m_data + m_size}; } - constexpr span<const char> as_span() const { return span<const char>(m_data, m_size); } + [[nodiscard]] constexpr span<const char> as_span() const { return {m_data, m_size}; } constexpr char operator[](isize_t i) const { @@ -68,24 +68,24 @@ public: return m_data[i]; // NOLINT(*-pointer-arithmetic) } - constexpr string_view substr(isize_t offset, isize_t size) const + [[nodiscard]] constexpr string_view substr(isize_t offset, isize_t size) const { ASL_ASSERT(offset >= 0 && size >= 0 && offset + size <= m_size); return string_view{m_data + offset, size}; // NOLINT(*-pointer-arithmetic) } - constexpr string_view substr(isize_t offset) const + [[nodiscard]] constexpr string_view substr(isize_t offset) const { ASL_ASSERT(offset >= 0 && offset <= m_size); return string_view{m_data + offset, m_size - offset}; // NOLINT(*-pointer-arithmetic) } - constexpr string_view first(isize_t size) const + [[nodiscard]] constexpr string_view first(isize_t size) const { return substr(0, size); } - constexpr string_view last(isize_t size) const + [[nodiscard]] constexpr string_view last(isize_t size) const { return substr(m_size - size); } @@ -107,5 +107,5 @@ public: constexpr asl::string_view operator ""_sv(const char* s, size_t len) { - return asl::string_view(s, static_cast<isize_t>(len)); + return {s, static_cast<isize_t>(len)}; } diff --git a/asl/types/span.hpp b/asl/types/span.hpp index 8585f17..105379b 100644 --- a/asl/types/span.hpp +++ b/asl/types/span.hpp @@ -77,14 +77,14 @@ public: template<isize_t N> constexpr span(T (&array)[N]) // NOLINT(*explicit*) requires (kIsDynamic) - : m_data{array} + : m_data{static_cast<T*>(array)} , m_size{N} {} template<isize_t N> constexpr span(T (&array)[N]) // NOLINT(*explicit*) requires (!kIsDynamic) && (N == kSize) - : m_data{array} + : m_data{static_cast<T*>(array)} {} template<is_object U, isize_t kOtherSize> @@ -109,24 +109,24 @@ public: ~span() = default; - constexpr isize_t size() const + [[nodiscard]] constexpr isize_t size() const { if constexpr (kIsDynamic) { return m_size; } else { return kSize; } } - constexpr isize_t size_bytes() const { return size() * size_of<T>; } + [[nodiscard]] constexpr isize_t size_bytes() const { return size() * size_of<T>; } - constexpr bool is_empty() const { return size() == 0; } + [[nodiscard]] constexpr bool is_empty() const { return size() == 0; } - constexpr T* data() const { return m_data; } + [[nodiscard]] constexpr T* data() const { return m_data; } - constexpr contiguous_iterator<T> begin() const + [[nodiscard]] constexpr contiguous_iterator<T> begin() const { return contiguous_iterator{m_data}; } - constexpr contiguous_iterator<T> end() const + [[nodiscard]] constexpr contiguous_iterator<T> end() const { return contiguous_iterator{m_data + size()}; } @@ -138,7 +138,7 @@ public: } template<isize_t kOffset, isize_t kSubSize = dynamic_size> - constexpr auto subspan() const + [[nodiscard]] constexpr auto subspan() const requires ( kOffset >= 0 && (kIsDynamic || kOffset <= kSize) && @@ -165,13 +165,13 @@ public: } } - constexpr span<T> subspan(isize_t offset) const + [[nodiscard]] constexpr span<T> subspan(isize_t offset) const { ASL_ASSERT(offset <= size()); return span<T>{ data() + offset, size() - offset }; } - constexpr span<T> subspan(isize_t offset, isize_t sub_size) const + [[nodiscard]] constexpr span<T> subspan(isize_t offset, isize_t sub_size) const { ASL_ASSERT(offset <= size() && !is_dynamic(sub_size)); ASL_ASSERT(sub_size <= size() - offset); @@ -179,7 +179,7 @@ public: } template<isize_t kSubSize> - constexpr auto first() const + [[nodiscard]] constexpr auto first() const requires ( kSubSize >= 0 && (kIsDynamic || kSubSize <= kSize) @@ -189,14 +189,14 @@ public: return span<T, kSubSize>{ data(), kSubSize }; } - constexpr span<T> first(isize_t sub_size) const + [[nodiscard]] constexpr span<T> first(isize_t sub_size) const { ASL_ASSERT(sub_size >= 0 && sub_size <= size()); return span<T>{ data(), sub_size }; } template<isize_t kSubSize> - constexpr auto last() const + [[nodiscard]] constexpr auto last() const requires ( kSubSize >= 0 && (kIsDynamic || kSubSize <= kSize) @@ -206,7 +206,7 @@ public: return span<T, kSubSize>{ data() + size() - kSubSize, kSubSize }; } - constexpr span<T> last(isize_t sub_size) const + [[nodiscard]] constexpr span<T> last(isize_t sub_size) const { ASL_ASSERT(sub_size >= 0 && sub_size <= size()); return span<T>{ data() + size() - sub_size, sub_size }; diff --git a/asl/types/status.hpp b/asl/types/status.hpp index 83be5ce..df96cd8 100644 --- a/asl/types/status.hpp +++ b/asl/types/status.hpp @@ -38,12 +38,12 @@ class status return static_cast<status_code>(bit_cast<uintptr_t>(payload) >> 1); } - constexpr bool is_inline() const + [[nodiscard]] constexpr bool is_inline() const { return m_payload == nullptr || (bit_cast<uintptr_t>(m_payload) & 1) != 0; } - constexpr status_code code_inline() const + [[nodiscard]] constexpr status_code code_inline() const { ASL_ASSERT(is_inline()); if (m_payload == nullptr) @@ -53,8 +53,8 @@ class status return payload_to_status(m_payload); } - status_code code_internal() const; - string_view message_internal() const; + [[nodiscard]] status_code code_internal() const; + [[nodiscard]] string_view message_internal() const; void ref(); void unref(); @@ -103,17 +103,17 @@ public: return *this; } - constexpr bool ok() const + [[nodiscard]] constexpr bool ok() const { return m_payload == nullptr; } - constexpr status_code code() const + [[nodiscard]] constexpr status_code code() const { return is_inline() ? code_inline() : code_internal(); } - constexpr string_view message() const + [[nodiscard]] constexpr string_view message() const { if (!is_inline()) { @@ -156,6 +156,6 @@ ASL_DEFINE_ERROR_(internal) ASL_DEFINE_ERROR_(runtime) ASL_DEFINE_ERROR_(invalid_argument) -#define ASL_TRY(VALUE) if (VALUE.ok()) {} else { return std::move(VALUE).throw_status(); } +#define ASL_TRY(VALUE) if ((VALUE).ok()) {} else { return std::move(VALUE).throw_status(); } } // namespace asl diff --git a/asl/types/status_or.hpp b/asl/types/status_or.hpp index 7794596..f60a48e 100644 --- a/asl/types/status_or.hpp +++ b/asl/types/status_or.hpp @@ -99,13 +99,13 @@ public: } } - // NOLINTNEXTLINE(*-explicit-conversions) + // NOLINTNEXTLINE(*explicit*) constexpr status_or(const status& status) : m_status{status} { ASL_ASSERT_RELEASE(!m_status.ok()); } - // NOLINTNEXTLINE(*-explicit-conversions) + // NOLINTNEXTLINE(*explicit*) constexpr status_or(status&& status) : m_status{std::move(status)} { ASL_ASSERT_RELEASE(!m_status.ok()); @@ -125,11 +125,11 @@ public: , m_value{in_place, std::forward<U>(value)} {} - constexpr bool ok() const { return m_status.ok(); } + [[nodiscard]] constexpr bool ok() const { return m_status.ok(); } - constexpr status_code code() const { return m_status.code(); } + [[nodiscard]] constexpr status_code code() const { return m_status.code(); } - constexpr string_view message() const { return m_status.message(); } + [[nodiscard]] constexpr string_view message() const { return m_status.message(); } constexpr status&& throw_status() && { return std::move(m_status); } |