summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NeKit/Function.h
blob: 05cb44d5da0897913c67f354e5286a408bbde27a (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
50
/* -------------------------------------------

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

------------------------------------------- */

#ifndef _INC_FUNCTION_H_
#define _INC_FUNCTION_H_

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

namespace Kernel {
template <typename T, typename... Args>
class Function final {
 public:
  Function() = default;

 public:
  explicit Function(T (*Fn)(Args... args)) : fFn(Fn) {}

  ~Function() = default;

  Function& operator=(const Function&) = default;
  Function(const Function&)            = default;

  template <typename... XArgs>
  T operator()(Args&&... args) {
    return fFn(args...);
  }

  template <typename... XArgs>
  T Call(Args&&... args) {
    return fFn(args...);
  }

  operator bool() { return fFn; }

  bool operator!() { return !fFn; }

 private:
  T(*fFn)
  (Args... args);
};

template <typename T, typename... Args>
using FunctionOr = ErrorOr<Function<T, Args...>>;
}  // namespace Kernel

#endif  // !_INC_FUNCTION_H__