blob: 48f9ea538aac717c47746abcbbbd5cbeb7726406 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/nekernel-org/nekernel
#ifndef __NE_KIT_INIT_LIST_H__
#define __NE_KIT_INIT_LIST_H__
#include <NeKit/Config.h>
#include <NeKit/ErrorOr.h>
namespace Kernel {
// \brief Initalizer List object for containers.
template <class Type, SizeT N>
class InitializerList final {
public:
InitializerList() = delete;
explicit InitializerList(const Type* list) {
if constexpr (N > 0) {
for (auto i = 0UL; i < N; ++i) {
fList[i] = list[i];
}
}
}
~InitializerList() = default;
InitializerList& operator=(const InitializerList&) = delete;
InitializerList(const InitializerList&) = delete;
Type* begin() { return fList; }
Type* end() { return fList + N; }
constexpr SizeT size() const { return N; }
Type* operator->() { return this->begin(); }
Type* operator*() { return this->begin(); }
private:
Type fList[N];
};
template <class T, SizeT N>
using ErrorOrList = ErrorOr<InitializerList<T, N>>;
} // namespace Kernel
#endif
|