From cbade33906dc0d090d5dba6231fb48e359afff95 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 12 Mar 2025 00:37:23 +0100 Subject: Some more shit --- asl/types/span.hpp | 30 +++++++++++++++--------------- asl/types/status.hpp | 16 ++++++++-------- asl/types/status_or.hpp | 10 +++++----- 3 files changed, 28 insertions(+), 28 deletions(-) (limited to 'asl/types') 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 constexpr span(T (&array)[N]) // NOLINT(*explicit*) requires (kIsDynamic) - : m_data{array} + : m_data{static_cast(array)} , m_size{N} {} template constexpr span(T (&array)[N]) // NOLINT(*explicit*) requires (!kIsDynamic) && (N == kSize) - : m_data{array} + : m_data{static_cast(array)} {} template @@ -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; } + [[nodiscard]] constexpr isize_t size_bytes() const { return size() * size_of; } - 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 begin() const + [[nodiscard]] constexpr contiguous_iterator begin() const { return contiguous_iterator{m_data}; } - constexpr contiguous_iterator end() const + [[nodiscard]] constexpr contiguous_iterator end() const { return contiguous_iterator{m_data + size()}; } @@ -138,7 +138,7 @@ public: } template - constexpr auto subspan() const + [[nodiscard]] constexpr auto subspan() const requires ( kOffset >= 0 && (kIsDynamic || kOffset <= kSize) && @@ -165,13 +165,13 @@ public: } } - constexpr span subspan(isize_t offset) const + [[nodiscard]] constexpr span subspan(isize_t offset) const { ASL_ASSERT(offset <= size()); return span{ data() + offset, size() - offset }; } - constexpr span subspan(isize_t offset, isize_t sub_size) const + [[nodiscard]] constexpr span 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 - constexpr auto first() const + [[nodiscard]] constexpr auto first() const requires ( kSubSize >= 0 && (kIsDynamic || kSubSize <= kSize) @@ -189,14 +189,14 @@ public: return span{ data(), kSubSize }; } - constexpr span first(isize_t sub_size) const + [[nodiscard]] constexpr span first(isize_t sub_size) const { ASL_ASSERT(sub_size >= 0 && sub_size <= size()); return span{ data(), sub_size }; } template - constexpr auto last() const + [[nodiscard]] constexpr auto last() const requires ( kSubSize >= 0 && (kIsDynamic || kSubSize <= kSize) @@ -206,7 +206,7 @@ public: return span{ data() + size() - kSubSize, kSubSize }; } - constexpr span last(isize_t sub_size) const + [[nodiscard]] constexpr span last(isize_t sub_size) const { ASL_ASSERT(sub_size >= 0 && sub_size <= size()); return span{ 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(bit_cast(payload) >> 1); } - constexpr bool is_inline() const + [[nodiscard]] constexpr bool is_inline() const { return m_payload == nullptr || (bit_cast(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(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); } -- cgit