// Copyright 2025 Steven Le Rouzic // // SPDX-License-Identifier: BSD-3-Clause #pragma once #include "asl/base/assert.hpp" #include "asl/base/meta.hpp" #include "asl/base/utility.hpp" #include "asl/types/span.hpp" namespace asl { template requires (kSize > 0) struct array { T m_data[kSize]; [[nodiscard]] constexpr bool is_empty() const { return false; } [[nodiscard]] constexpr int64_t size() const { return kSize; } constexpr auto data(this auto&& self) { using return_type = un_ref_t>*; return static_cast(self.m_data); } constexpr auto begin(this auto&& self) { return contiguous_iterator{self.data()}; } constexpr auto end(this auto&& self) { return contiguous_iterator{self.data() + kSize}; } template requires (kSpanSize == kSize || kSpanSize == dynamic_size) constexpr operator span() const // NOLINT(*explicit*) { return as_span(); } template requires (kSpanSize == kSize || kSpanSize == dynamic_size) constexpr operator span() // NOLINT(*explicit*) { return as_span(); } constexpr auto as_span(this auto&& self) { using type = un_ref_t>; return span{self.data(), self.size()}; } constexpr auto&& operator[](this auto&& self, isize_t i) { ASL_ASSERT(i >= 0 && i <= self.size()); return std::forward_like(std::forward(self).data()[i]); } }; } // namespace asl