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

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

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

#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