diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-10 10:05:53 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-10 10:08:00 +0100 |
| commit | 031789eeb226b2b559f0edbaf28ed5bebc6ddff4 (patch) | |
| tree | f068128f603c75f97ba766290b6c8c2be05afe8f /src/kernel | |
| parent | 64c23b15059649aeee6d08c7940d0ff1b56512b5 (diff) | |
chore: new `InitializerList` API.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/kernel')
| -rw-r--r-- | src/kernel/NeKit/Function.h | 18 | ||||
| -rw-r--r-- | src/kernel/NeKit/InitializerList.h | 18 |
2 files changed, 16 insertions, 20 deletions
diff --git a/src/kernel/NeKit/Function.h b/src/kernel/NeKit/Function.h index 1ceda345..2889e055 100644 --- a/src/kernel/NeKit/Function.h +++ b/src/kernel/NeKit/Function.h @@ -16,28 +16,24 @@ namespace Kernel { template <typename T, typename... Args> class Function final { public: - Function() = default; - - public: - explicit Function(T (*Fn)(Args... args)) : fFn(Fn) {} - + Function() = delete; + Function(nullPtr) = delete; ~Function() = default; - Function& operator=(const Function&) = default; - Function(const Function&) = default; + explicit Function(T (*Fn)(Args... args)) : fFn(Fn) { MUST_PASS(fFn); } + + Function& operator=(const Function&) = delete; + Function(const Function&) = delete; - template <typename... XArgs> T operator()(Args&&... args) { return fFn(args...); } - template <typename... XArgs> T Call(Args&&... args) { return fFn(args...); } - operator bool() { return fFn; } - + explicit operator bool() { return fFn; } bool operator!() { return !fFn; } private: diff --git a/src/kernel/NeKit/InitializerList.h b/src/kernel/NeKit/InitializerList.h index 158b88ed..dc33d8eb 100644 --- a/src/kernel/NeKit/InitializerList.h +++ b/src/kernel/NeKit/InitializerList.h @@ -7,9 +7,10 @@ #pragma once #include <NeKit/Config.h> +#include <NeKit/ErrorOr.h> namespace Kernel { -template <typename T, SizeT N> +template <class T, SizeT N> class InitializerList final { public: explicit InitializerList(const T* list) { @@ -22,21 +23,20 @@ class InitializerList final { ~InitializerList() = default; - InitializerList& operator=(const InitializerList&) = default; - InitializerList(const InitializerList&) = default; + InitializerList& operator=(const InitializerList&) = delete; + InitializerList(const InitializerList&) = delete; T* begin() { return fList; } - T* operator->() { return fList; } - T* operator*() { return fList; } T* end() { return fList + N; } constexpr SizeT size() const { return N; } + + T* operator->() { return fList; } + T* operator*() { return fList; } private: T fList[N]; }; -template <typename ValueType, SizeT N> -inline InitializerList<ValueType, N> make_list(ValueType& val) { - return InitializerList<ValueType, N>{val}; -} +template <class T, SizeT N> +using ErrorOrList = ErrorOr<InitializerList<T, N>>; } // namespace Kernel |
