summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/NeKit/Vettable.h
blob: 0d30012aba50a27fbd3652e1dce6c1e9f2de630f (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
51
52
53
54
55
56
57
58
59
60

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

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

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

#ifndef __NE_KIT_VETTABLE_H__
#define __NE_KIT_VETTABLE_H__

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

#define NE_VETTABLE : public ::Kernel::IVettable
#define NE_NOT_VETTABLE : public ::Kernel::INotVettable

namespace Kernel {
/// @brief Vet interface for objects.
struct IVettable {
  explicit IVettable() = default;
  virtual ~IVettable() = default;

  NE_COPY_DEFAULT(IVettable)
};

struct INotVettable {
  explicit INotVettable() = default;
  virtual ~INotVettable() = default;

  NE_COPY_DEFAULT(INotVettable)
};

template <class Type>
struct Vettable final {
  static constexpr bool kValue = false;
};

template <>
struct Vettable<INotVettable> final {
  static constexpr bool kValue = false;
};

template <>
struct Vettable<IVettable> final {
  static constexpr bool kValue = true;
};

/// @brief Concept version of Vettable.
template <typename T, typename OnFallback>
concept IsVettable = requires(OnFallback fallback) {
  { Vettable<T>::kValue ? true : fallback() };
};

template <class Type, typename OnFallback>
concept IsNotVettable = requires(OnFallback fallback) {
  { !Vettable<Type>::kValue ? true : fallback() };
};
}  // namespace Kernel

#endif  // !__NE_KIT_VETTABLE_H__