summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/NeKit/InitializerList.h
blob: dc33d8eb224bbc47d2aef2c2bdcb340be52d7723 (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
/* ========================================

  Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

======================================== */

#pragma once

#include <NeKit/Config.h>
#include <NeKit/ErrorOr.h>

namespace Kernel {
template <class 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&) = delete;
  InitializerList(const InitializerList&)            = delete;

  T*              begin() { 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 <class T, SizeT N>
using ErrorOrList = ErrorOr<InitializerList<T, N>>;
}  // namespace Kernel