aboutsummaryrefslogtreecommitdiff
path: root/src/macros_and_utils.h
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-10-07 09:29:49 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-10-07 09:29:49 +0200
commite939e5e6a894a042d3301e47faa05264445f27f6 (patch)
treee913615e3fd0ed9e94d9494d6e266420dd7a771b /src/macros_and_utils.h
parentb064bedccebe511b96c9d99d689d6634f5873ec2 (diff)
downloadlanes-e939e5e6a894a042d3301e47faa05264445f27f6.tar.gz
lanes-e939e5e6a894a042d3301e47faa05264445f27f6.tar.bz2
lanes-e939e5e6a894a042d3301e47faa05264445f27f6.zip
Internal improvements: new strong types StackIndex and KeeperIndex
Diffstat (limited to 'src/macros_and_utils.h')
-rw-r--r--src/macros_and_utils.h34
1 files changed, 2 insertions, 32 deletions
diff --git a/src/macros_and_utils.h b/src/macros_and_utils.h
index 1b1ced6..e73abef 100644
--- a/src/macros_and_utils.h
+++ b/src/macros_and_utils.h
@@ -2,6 +2,7 @@
2 2
3#include "debug.h" 3#include "debug.h"
4#include "luaerrors.h" 4#include "luaerrors.h"
5#include "unique.hpp"
5 6
6using namespace std::chrono_literals; 7using namespace std::chrono_literals;
7 8
@@ -24,40 +25,9 @@ using lua_Duration = std::chrono::template duration<lua_Number>;
24 25
25// ################################################################################################# 26// #################################################################################################
26 27
27// A unique type generator
28template <typename T, auto = [] {}, typename specialization = void>
29class Unique
30{
31 private:
32 T val;
33
34 public:
35 using type = T;
36 Unique() = default;
37 operator T() const { return val; }
38 explicit Unique(T b_)
39 : val{ b_ }
40 {
41 }
42};
43
44template <typename T, auto lambda>
45class Unique<T, lambda, std::enable_if_t<!std::is_scalar_v<T>>>
46: public T
47{
48 public:
49 using type = T;
50 using T::T;
51 explicit Unique(T const& b_)
52 : T{ b_ }
53 {
54 }
55};
56
57// #################################################################################################
58
59using SourceState = Unique<lua_State*>; 28using SourceState = Unique<lua_State*>;
60using DestState = Unique<lua_State*>; 29using DestState = Unique<lua_State*>;
30using StackIndex = Unique<int>;
61 31
62// ################################################################################################# 32// #################################################################################################
63 33