Some more shit
This commit is contained in:
@ -18,3 +18,6 @@ Checks:
|
|||||||
- "-bugprone-easily-swappable-parameters"
|
- "-bugprone-easily-swappable-parameters"
|
||||||
- "-*-signed-bitwise"
|
- "-*-signed-bitwise"
|
||||||
- "-*-avoid-do-while"
|
- "-*-avoid-do-while"
|
||||||
|
- "-cppcoreguidelines-pro-type-union-access"
|
||||||
|
- "-*-copy-assignment-signature"
|
||||||
|
- "-*-unconventional-assign-operator"
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
// NOLINTBEGIN(*-macro-to-enum)
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@ -19,3 +21,6 @@
|
|||||||
#else
|
#else
|
||||||
#error Unknown compiler
|
#error Unknown compiler
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// NOLINTEND(*-macro-to-enum)
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@ class DeferCallback
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
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))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,25 +11,25 @@ namespace std
|
|||||||
{
|
{
|
||||||
|
|
||||||
template<typename T>
|
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);
|
return static_cast<asl::un_ref_t<T>&&>(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename 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);
|
return static_cast<T&&>(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class 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);
|
return static_cast<T&&>(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename U>
|
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&&>;
|
using return_type = asl::copy_cref_t<T, U&&>;
|
||||||
return static_cast<return_type>(x);
|
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 std
|
||||||
|
|
||||||
|
|
||||||
namespace asl
|
namespace asl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ private:
|
|||||||
static_assert(align_of<T*> == align_of<isize_t>);
|
static_assert(align_of<T*> == align_of<isize_t>);
|
||||||
static_assert(align_of<T*> == align_of<size_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{};
|
size_t s{};
|
||||||
asl::memcpy(&s, &m_size_encoded_, sizeof(size_t));
|
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());
|
return is_on_heap(load_size_encoded());
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr T* push_uninit()
|
constexpr T* push_uninit()
|
||||||
{
|
{
|
||||||
isize_t sz = size();
|
const isize_t sz = size();
|
||||||
resize_uninit_inner(sz + 1);
|
resize_uninit_inner(sz + 1);
|
||||||
return data() + sz;
|
return data() + sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void resize_uninit_inner(isize_t new_size)
|
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)
|
if (!trivially_destructible<T> && new_size < old_size)
|
||||||
{
|
{
|
||||||
destroy_n(data() + new_size, old_size - new_size);
|
destroy_n(data() + new_size, old_size - new_size);
|
||||||
@ -110,7 +110,7 @@ private:
|
|||||||
constexpr void set_size_inline(isize_t new_size)
|
constexpr void set_size_inline(isize_t new_size)
|
||||||
{
|
{
|
||||||
ASL_ASSERT(new_size >= 0 && new_size <= kInlineCapacity);
|
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);
|
store_size_encoded(size_encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +144,8 @@ private:
|
|||||||
}
|
}
|
||||||
else if (!assign || m_allocator == other.m_allocator)
|
else if (!assign || m_allocator == other.m_allocator)
|
||||||
{
|
{
|
||||||
isize_t other_n = other.size();
|
const isize_t other_n = other.size();
|
||||||
isize_t this_n = size();
|
const isize_t this_n = size();
|
||||||
resize_uninit_inner(other_n);
|
resize_uninit_inner(other_n);
|
||||||
if (other_n <= this_n)
|
if (other_n <= this_n)
|
||||||
{
|
{
|
||||||
@ -160,7 +160,7 @@ private:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
destroy();
|
destroy();
|
||||||
isize_t n = other.size();
|
const isize_t n = other.size();
|
||||||
ASL_ASSERT(n <= kInlineCapacity);
|
ASL_ASSERT(n <= kInlineCapacity);
|
||||||
relocate_uninit_n(data(), other.data(), n);
|
relocate_uninit_n(data(), other.data(), n);
|
||||||
set_size_inline(n);
|
set_size_inline(n);
|
||||||
@ -176,8 +176,8 @@ private:
|
|||||||
|
|
||||||
void copy_range(span<const T> to_copy)
|
void copy_range(span<const T> to_copy)
|
||||||
{
|
{
|
||||||
isize_t this_size = size();
|
const isize_t this_size = size();
|
||||||
isize_t new_size = to_copy.size();
|
const isize_t new_size = to_copy.size();
|
||||||
|
|
||||||
resize_uninit_inner(to_copy.size());
|
resize_uninit_inner(to_copy.size());
|
||||||
ASL_ASSERT(capacity() >= new_size);
|
ASL_ASSERT(capacity() >= new_size);
|
||||||
@ -268,12 +268,12 @@ public:
|
|||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr isize_t size() const
|
[[nodiscard]] constexpr isize_t size() const
|
||||||
{
|
{
|
||||||
return decode_size(load_size_encoded());
|
return decode_size(load_size_encoded());
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr isize_t capacity() const
|
[[nodiscard]] constexpr isize_t capacity() const
|
||||||
{
|
{
|
||||||
if constexpr (kInlineCapacity == 0)
|
if constexpr (kInlineCapacity == 0)
|
||||||
{
|
{
|
||||||
@ -287,7 +287,7 @@ public:
|
|||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
isize_t current_size = size();
|
const isize_t current_size = size();
|
||||||
if (current_size == 0) { return; }
|
if (current_size == 0) { return; }
|
||||||
|
|
||||||
destroy_n(data(), current_size);
|
destroy_n(data(), current_size);
|
||||||
@ -357,7 +357,7 @@ public:
|
|||||||
constexpr void resize_zero(isize_t new_size)
|
constexpr void resize_zero(isize_t new_size)
|
||||||
requires trivially_default_constructible<T> && trivially_destructible<T>
|
requires trivially_default_constructible<T> && trivially_destructible<T>
|
||||||
{
|
{
|
||||||
isize_t old_size = size();
|
const isize_t old_size = size();
|
||||||
resize_uninit(new_size);
|
resize_uninit(new_size);
|
||||||
|
|
||||||
if (new_size > old_size)
|
if (new_size > old_size)
|
||||||
|
@ -72,7 +72,7 @@ protected:
|
|||||||
|
|
||||||
ASL_NO_UNIQUE_ADDRESS Allocator m_allocator;
|
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%
|
// Max load factor is 75%
|
||||||
return (m_capacity >> 1) + (m_capacity >> 2); // NOLINT(*-signed-bitwise)
|
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>
|
template<typename... Args>
|
||||||
void insert(Args&&... args)
|
void insert(Args&&... args)
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
ASL_DEFAULT_MOVE(IntrusiveList);
|
ASL_DEFAULT_MOVE(IntrusiveList);
|
||||||
~IntrusiveList() = default;
|
~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)
|
void push_front(T* node)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ struct type_erased_arg
|
|||||||
template<formattable T>
|
template<formattable T>
|
||||||
static constexpr void erased_fn(Formatter& f, const void* data)
|
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>
|
template<formattable T>
|
||||||
@ -44,7 +44,7 @@ struct type_erased_arg
|
|||||||
|
|
||||||
void format(Writer*, string_view fmt, span<const type_erased_arg> args);
|
void format(Writer*, string_view fmt, span<const type_erased_arg> args);
|
||||||
|
|
||||||
} // namespace internals
|
} // namespace format_internals
|
||||||
|
|
||||||
class Formatter
|
class Formatter
|
||||||
{
|
{
|
||||||
@ -60,7 +60,7 @@ public:
|
|||||||
m_writer->write(as_bytes(s.as_span()));
|
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>
|
template<formattable... Args>
|
||||||
@ -68,7 +68,7 @@ void format(Writer* w, string_view fmt, const Args&... args)
|
|||||||
{
|
{
|
||||||
if constexpr (types_count<Args...> > 0)
|
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)...
|
format_internals::type_erased_arg(args)...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ void log(level l, const source_location& sl, string_view fmt, const Args&... arg
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
format_internals::type_erased_arg type_erased_args[] = {
|
const format_internals::type_erased_arg type_erased_args[] = {
|
||||||
format_internals::type_erased_arg(args)...
|
format_internals::type_erased_arg(args)...
|
||||||
};
|
};
|
||||||
log_inner(l, fmt, type_erased_args, sl);
|
log_inner(l, fmt, type_erased_args, sl);
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "asl/base/utility.hpp"
|
#include "asl/base/utility.hpp"
|
||||||
#include "asl/memory/layout.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;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
constexpr StringBuilder& operator=(const StringBuilder&) requires copy_assignable<Allocator> = default;
|
constexpr StringBuilder& operator=(const StringBuilder&) requires copy_assignable<Allocator> = default;
|
||||||
constexpr StringBuilder& operator=(StringBuilder&&) = 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();
|
auto span = m_buffer.as_span();
|
||||||
return string_view{span.data(), span.size()};
|
return string_view{span.data(), span.size()};
|
||||||
@ -98,10 +98,11 @@ public:
|
|||||||
|
|
||||||
void write(span<const byte> str) override
|
void write(span<const byte> str) override
|
||||||
{
|
{
|
||||||
|
// NOLINTNEXTLINE(*-reinterpret-cast)
|
||||||
m_builder.push(string_view{reinterpret_cast<const char*>(str.data()), str.size()});
|
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();
|
return m_builder.as_string_view();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class string_view
|
|||||||
public:
|
public:
|
||||||
constexpr string_view() = default;
|
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)
|
constexpr string_view(const char* data, isize_t size)
|
||||||
: m_data{data}
|
: m_data{data}
|
||||||
@ -28,9 +28,9 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
template<isize_t kSize>
|
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)
|
requires (kSize >= 1)
|
||||||
: m_data{str}
|
: m_data{static_cast<const char*>(str)}
|
||||||
, m_size{kSize - 1}
|
, m_size{kSize - 1}
|
||||||
{
|
{
|
||||||
ASL_ASSERT(m_data[kSize - 1] == '\0'); // NOLINT(*-pointer-arithmetic)
|
ASL_ASSERT(m_data[kSize - 1] == '\0'); // NOLINT(*-pointer-arithmetic)
|
||||||
@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
static constexpr string_view from_zstr(const char* str)
|
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;
|
constexpr string_view(const string_view&) = default;
|
||||||
@ -49,18 +49,18 @@ public:
|
|||||||
|
|
||||||
~string_view() = default;
|
~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)
|
// 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
|
constexpr char operator[](isize_t i) const
|
||||||
{
|
{
|
||||||
@ -68,24 +68,24 @@ public:
|
|||||||
return m_data[i]; // NOLINT(*-pointer-arithmetic)
|
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);
|
ASL_ASSERT(offset >= 0 && size >= 0 && offset + size <= m_size);
|
||||||
return string_view{m_data + offset, size}; // NOLINT(*-pointer-arithmetic)
|
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);
|
ASL_ASSERT(offset >= 0 && offset <= m_size);
|
||||||
return string_view{m_data + offset, m_size - offset}; // NOLINT(*-pointer-arithmetic)
|
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);
|
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);
|
return substr(m_size - size);
|
||||||
}
|
}
|
||||||
@ -107,5 +107,5 @@ public:
|
|||||||
|
|
||||||
constexpr asl::string_view operator ""_sv(const char* s, size_t len)
|
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)};
|
||||||
}
|
}
|
||||||
|
@ -77,14 +77,14 @@ public:
|
|||||||
template<isize_t N>
|
template<isize_t N>
|
||||||
constexpr span(T (&array)[N]) // NOLINT(*explicit*)
|
constexpr span(T (&array)[N]) // NOLINT(*explicit*)
|
||||||
requires (kIsDynamic)
|
requires (kIsDynamic)
|
||||||
: m_data{array}
|
: m_data{static_cast<T*>(array)}
|
||||||
, m_size{N}
|
, m_size{N}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<isize_t N>
|
template<isize_t N>
|
||||||
constexpr span(T (&array)[N]) // NOLINT(*explicit*)
|
constexpr span(T (&array)[N]) // NOLINT(*explicit*)
|
||||||
requires (!kIsDynamic) && (N == kSize)
|
requires (!kIsDynamic) && (N == kSize)
|
||||||
: m_data{array}
|
: m_data{static_cast<T*>(array)}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<is_object U, isize_t kOtherSize>
|
template<is_object U, isize_t kOtherSize>
|
||||||
@ -109,24 +109,24 @@ public:
|
|||||||
|
|
||||||
~span() = default;
|
~span() = default;
|
||||||
|
|
||||||
constexpr isize_t size() const
|
[[nodiscard]] constexpr isize_t size() const
|
||||||
{
|
{
|
||||||
if constexpr (kIsDynamic) { return m_size; }
|
if constexpr (kIsDynamic) { return m_size; }
|
||||||
else { return kSize; }
|
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};
|
return contiguous_iterator{m_data};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr contiguous_iterator<T> end() const
|
[[nodiscard]] constexpr contiguous_iterator<T> end() const
|
||||||
{
|
{
|
||||||
return contiguous_iterator{m_data + size()};
|
return contiguous_iterator{m_data + size()};
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<isize_t kOffset, isize_t kSubSize = dynamic_size>
|
template<isize_t kOffset, isize_t kSubSize = dynamic_size>
|
||||||
constexpr auto subspan() const
|
[[nodiscard]] constexpr auto subspan() const
|
||||||
requires (
|
requires (
|
||||||
kOffset >= 0 &&
|
kOffset >= 0 &&
|
||||||
(kIsDynamic || kOffset <= kSize) &&
|
(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());
|
ASL_ASSERT(offset <= size());
|
||||||
return span<T>{ data() + offset, size() - offset };
|
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(offset <= size() && !is_dynamic(sub_size));
|
||||||
ASL_ASSERT(sub_size <= size() - offset);
|
ASL_ASSERT(sub_size <= size() - offset);
|
||||||
@ -179,7 +179,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<isize_t kSubSize>
|
template<isize_t kSubSize>
|
||||||
constexpr auto first() const
|
[[nodiscard]] constexpr auto first() const
|
||||||
requires (
|
requires (
|
||||||
kSubSize >= 0 &&
|
kSubSize >= 0 &&
|
||||||
(kIsDynamic || kSubSize <= kSize)
|
(kIsDynamic || kSubSize <= kSize)
|
||||||
@ -189,14 +189,14 @@ public:
|
|||||||
return span<T, kSubSize>{ data(), kSubSize };
|
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());
|
ASL_ASSERT(sub_size >= 0 && sub_size <= size());
|
||||||
return span<T>{ data(), sub_size };
|
return span<T>{ data(), sub_size };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<isize_t kSubSize>
|
template<isize_t kSubSize>
|
||||||
constexpr auto last() const
|
[[nodiscard]] constexpr auto last() const
|
||||||
requires (
|
requires (
|
||||||
kSubSize >= 0 &&
|
kSubSize >= 0 &&
|
||||||
(kIsDynamic || kSubSize <= kSize)
|
(kIsDynamic || kSubSize <= kSize)
|
||||||
@ -206,7 +206,7 @@ public:
|
|||||||
return span<T, kSubSize>{ data() + size() - kSubSize, kSubSize };
|
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());
|
ASL_ASSERT(sub_size >= 0 && sub_size <= size());
|
||||||
return span<T>{ data() + size() - sub_size, sub_size };
|
return span<T>{ data() + size() - sub_size, sub_size };
|
||||||
|
@ -38,12 +38,12 @@ class status
|
|||||||
return static_cast<status_code>(bit_cast<uintptr_t>(payload) >> 1);
|
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;
|
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());
|
ASL_ASSERT(is_inline());
|
||||||
if (m_payload == nullptr)
|
if (m_payload == nullptr)
|
||||||
@ -53,8 +53,8 @@ class status
|
|||||||
return payload_to_status(m_payload);
|
return payload_to_status(m_payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_code code_internal() const;
|
[[nodiscard]] status_code code_internal() const;
|
||||||
string_view message_internal() const;
|
[[nodiscard]] string_view message_internal() const;
|
||||||
|
|
||||||
void ref();
|
void ref();
|
||||||
void unref();
|
void unref();
|
||||||
@ -103,17 +103,17 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool ok() const
|
[[nodiscard]] constexpr bool ok() const
|
||||||
{
|
{
|
||||||
return m_payload == nullptr;
|
return m_payload == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr status_code code() const
|
[[nodiscard]] constexpr status_code code() const
|
||||||
{
|
{
|
||||||
return is_inline() ? code_inline() : code_internal();
|
return is_inline() ? code_inline() : code_internal();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr string_view message() const
|
[[nodiscard]] constexpr string_view message() const
|
||||||
{
|
{
|
||||||
if (!is_inline())
|
if (!is_inline())
|
||||||
{
|
{
|
||||||
@ -156,6 +156,6 @@ ASL_DEFINE_ERROR_(internal)
|
|||||||
ASL_DEFINE_ERROR_(runtime)
|
ASL_DEFINE_ERROR_(runtime)
|
||||||
ASL_DEFINE_ERROR_(invalid_argument)
|
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
|
} // namespace asl
|
||||||
|
@ -99,13 +99,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(*-explicit-conversions)
|
// NOLINTNEXTLINE(*explicit*)
|
||||||
constexpr status_or(const status& status) : m_status{status}
|
constexpr status_or(const status& status) : m_status{status}
|
||||||
{
|
{
|
||||||
ASL_ASSERT_RELEASE(!m_status.ok());
|
ASL_ASSERT_RELEASE(!m_status.ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOLINTNEXTLINE(*-explicit-conversions)
|
// NOLINTNEXTLINE(*explicit*)
|
||||||
constexpr status_or(status&& status) : m_status{std::move(status)}
|
constexpr status_or(status&& status) : m_status{std::move(status)}
|
||||||
{
|
{
|
||||||
ASL_ASSERT_RELEASE(!m_status.ok());
|
ASL_ASSERT_RELEASE(!m_status.ok());
|
||||||
@ -125,11 +125,11 @@ public:
|
|||||||
, m_value{in_place, std::forward<U>(value)}
|
, 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); }
|
constexpr status&& throw_status() && { return std::move(m_status); }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user