-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.h
More file actions
85 lines (55 loc) · 1.91 KB
/
Utils.h
File metadata and controls
85 lines (55 loc) · 1.91 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include <Python.h>
#include "./Object.h"
#include "./Tuple.h"
#include <concepts>
namespace xpo::python {
struct Module;
template <typename... Ts>
using PackedVarArgsFunction = Object(*)(Module, TypedTuple<Ts...>);
template <typename... Ts>
using VarArgsFunction = Object(*)(Module, Ts...);
template <typename... Ts>
requires (sizeof...(Ts) > 0)
struct VarArgsFunctionObject {
using typed_tuple = TypedTuple<Ts...>;
using function_type = VarArgsFunction<Ts...>;
constexpr VarArgsFunctionObject(function_type function)
: m_function{ function }
{
}
static constexpr inline std::tuple<Ts...> args() { return std::declval<std::tuple<Ts...>>(); }
inline std::tuple<Ts...> make_tuple(Tuple const&& tuple) const { return tuple.to_tuple<Ts...>(); }
function_type m_function;
};
template <typename... Ts>
requires (sizeof...(Ts) > 0)
struct PackedVarArgsFunctionObject {
using typed_tuple = TypedTuple<Ts...>;
using function_type = PackedVarArgsFunction<Ts...>;
constexpr PackedVarArgsFunctionObject(function_type function)
: m_function{ function }
{
}
static constexpr inline typed_tuple args() { return std::declval<typed_tuple>(); }
inline typed_tuple make_tuple(Tuple const&& tuple) const { return typed_tuple(tuple.ptr()); }
function_type m_function;
};
template <class T>
concept IVarArgsFunction = requires (T t, PyObject * p) {
{ t(p, p) } -> std::convertible_to<PyObject*>;
};
template <class T>
concept IKWArgsFunction = requires (T t, PyObject * p) {
{ t(p, p, p) } -> std::convertible_to<PyObject*>;
};
template <VarArgsFunctionObject P>
concept IVarArgsFunctionCall = requires (Module m) {
{ std::apply(P.m_function, std::tuple_cat(std::make_tuple(m), P.args())) } -> std::convertible_to<Object>;
};
template <PackedVarArgsFunctionObject P>
concept IPackedVarArgsFunctionCall = requires (Module m) {
{ P.m_function(m, P.args()) } -> std::convertible_to<Object>;
};
struct Module;
}