summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/NeKit
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/NeKit')
-rw-r--r--src/kernel/NeKit/Array.h11
-rw-r--r--src/kernel/NeKit/ArrayList.h44
-rw-r--r--src/kernel/NeKit/Atom.h2
-rw-r--r--src/kernel/NeKit/InitializerList.h42
-rw-r--r--src/kernel/NeKit/NeKit.h2
5 files changed, 49 insertions, 52 deletions
diff --git a/src/kernel/NeKit/Array.h b/src/kernel/NeKit/Array.h
index f4673b68..179b8e4e 100644
--- a/src/kernel/NeKit/Array.h
+++ b/src/kernel/NeKit/Array.h
@@ -20,26 +20,25 @@ class Array final {
Array& operator=(const Array&) = default;
Array(const Array&) = default;
- T& operator[](SizeT at) { return fArray[at]; }
+ T& operator[](const SizeT& at) { return fArray[at]; }
+ const T& operator[](const SizeT& at) const { return fArray[at]; }
Boolean Empty() { return this->Count() > 0; }
SizeT Capacity() { return N; }
- SizeT Count() {
- return N; // avoid constexpr error.
- }
+ SizeT Count() { return N; }
const T* CData() { return fArray; }
- operator bool() { return !Empty(); }
+ explicit operator bool() { return !this->Empty(); }
private:
T fArray[N];
};
template <typename ValueType>
-auto make_list(ValueType val) {
+inline auto make_array(ValueType& val) -> auto {
return Array<ValueType, ARRAY_SIZE(val)>{val};
}
} // namespace Kernel
diff --git a/src/kernel/NeKit/ArrayList.h b/src/kernel/NeKit/ArrayList.h
deleted file mode 100644
index 5787fe98..00000000
--- a/src/kernel/NeKit/ArrayList.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/* ========================================
-
- Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
-
-======================================== */
-
-#pragma once
-
-#include <NeKit/Config.h>
-
-namespace Kernel {
-template <typename T>
-class ArrayList final {
- public:
- explicit ArrayList(T* list, SizeT length) : fList(reinterpret_cast<T>(list)), fLen(length) {}
-
- ~ArrayList() = default;
-
- ArrayList& operator=(const ArrayList&) = default;
- ArrayList(const ArrayList&) = default;
-
- T* Data() { return fList; }
-
- const T* CData() { return fList; }
-
- T& operator[](SizeT index) const {
- MUST_PASS(index < this->Count());
- return fList[index];
- }
-
- explicit operator bool() { return fList; }
-
- SizeT Count() const { return fLen; }
-
- private:
- T* fList{nullptr};
- SizeT fLen{0};
-};
-
-template <typename ValueType>
-ArrayList<ValueType> make_list(ValueType val) {
- return ArrayList<ValueType>{val};
-}
-} // namespace Kernel
diff --git a/src/kernel/NeKit/Atom.h b/src/kernel/NeKit/Atom.h
index 51808a0a..7c4ebb5b 100644
--- a/src/kernel/NeKit/Atom.h
+++ b/src/kernel/NeKit/Atom.h
@@ -25,7 +25,7 @@ class Atom final {
friend Boolean operator==(Atom<T>& atomic, const T& idx) { return atomic[idx] == idx; }
- friend Boolean operator!=(Atom<T>& atomic, const T& idx) { return atomic[idx] == idx; }
+ friend Boolean operator!=(Atom<T>& atomic, const T& idx) { return atomic[idx] != idx; }
private:
T fArrayOfAtoms;
diff --git a/src/kernel/NeKit/InitializerList.h b/src/kernel/NeKit/InitializerList.h
new file mode 100644
index 00000000..158b88ed
--- /dev/null
+++ b/src/kernel/NeKit/InitializerList.h
@@ -0,0 +1,42 @@
+/* ========================================
+
+ Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
+
+======================================== */
+
+#pragma once
+
+#include <NeKit/Config.h>
+
+namespace Kernel {
+template <typename T, SizeT N>
+class InitializerList final {
+ public:
+ explicit InitializerList(const T* list) {
+ if constexpr (N > 0) {
+ for (auto i = 0UL; i < N; ++i) {
+ fList[i] = list[i];
+ }
+ }
+ }
+
+ ~InitializerList() = default;
+
+ InitializerList& operator=(const InitializerList&) = default;
+ InitializerList(const InitializerList&) = default;
+
+ T* begin() { return fList; }
+ T* operator->() { return fList; }
+ T* operator*() { return fList; }
+ T* end() { return fList + N; }
+ constexpr SizeT size() const { return N; }
+
+ private:
+ T fList[N];
+};
+
+template <typename ValueType, SizeT N>
+inline InitializerList<ValueType, N> make_list(ValueType& val) {
+ return InitializerList<ValueType, N>{val};
+}
+} // namespace Kernel
diff --git a/src/kernel/NeKit/NeKit.h b/src/kernel/NeKit/NeKit.h
index 4b1e64ca..9bf74e57 100644
--- a/src/kernel/NeKit/NeKit.h
+++ b/src/kernel/NeKit/NeKit.h
@@ -8,8 +8,8 @@
#pragma once
#include <NeKit/Array.h>
-#include <NeKit/ArrayList.h>
#include <NeKit/ErrorOr.h>
+#include <NeKit/InitializerList.h>
#include <NeKit/Json.h>
#include <NeKit/KernelPanic.h>
#include <NeKit/MutableArray.h>