Sygaldry
Loading...
Searching...
No Matches
sygac-functions.hpp
1#pragma once
2/*
3Copyright 2023 Travis J. West, https://traviswest.ca, Input Devices and Music
4Interaction Laboratory (IDMIL), Centre for Interdisciplinary Research in Music
5Media and Technology (CIRMMT), McGill University, Montréal, Canada, and Univ.
6Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France
7
8SPDX-License-Identifier: MIT
9*/
10
11#include <type_traits>
12#include <concepts>
13
14namespace sygaldry {
18
22
24template<typename ... Ts> struct function_arg_list {};
25
26template<typename NotAFunction>
28{
29 using exists = std::false_type;
30};
31
32template<typename Ret, typename... Args>
33struct function_type_reflection<Ret(Args...)> {
34 using exists = std::true_type;
35 using return_type = Ret;
36 using arguments = function_arg_list<Args...>;
37 using is_free = std::true_type;
38 using is_member = std::false_type;
39 using parent_class = std::false_type;
40 using is_const = std::false_type;
41 using is_volatile = std::false_type;
42 using is_noexcept = std::false_type;
43};
44
45template<typename Ret, typename... Args>
46struct function_type_reflection<Ret(*)(Args...)> : function_type_reflection<Ret(Args...)> {};
47
48template<typename Ret, typename Class, typename... Args>
49struct function_type_reflection<Ret(Class::*)(Args...)> : function_type_reflection<Ret(Args...)>
50{
51 using is_free = std::false_type;
52 using is_member = std::true_type;
53 using parent_class = Class;
54};
55
56template<typename Ret, typename Class, typename... Args>
57struct function_type_reflection<Ret(Class::*)(Args...) const> : function_type_reflection<Ret(Class::*)(Args...)>
58{
59 using is_const = std::true_type;
60};
61
62template<typename Ret, typename Class, typename... Args>
63struct function_type_reflection<Ret(Class::*)(Args...) volatile> : function_type_reflection<Ret(Class::*)(Args...)>
64{
65 using is_volatile = std::true_type;
66};
67
68template<typename Ret, typename Class, typename... Args>
69struct function_type_reflection<Ret(Class::*)(Args...) const volatile> : function_type_reflection<Ret(Class::*)(Args...)>
70{
71 using is_const = std::true_type;
72 using is_volatile = std::true_type;
73};
74
75template<typename Ret, typename Class, typename... Args>
76struct function_type_reflection<Ret(Class::*)(Args...) noexcept> : function_type_reflection<Ret(Class::*)(Args...)>
77{
78 using is_noexcept = std::true_type;
79};
80
81template<typename Ret, typename Class, typename... Args>
82struct function_type_reflection<Ret(Class::*)(Args...) const noexcept> : function_type_reflection<Ret(Class::*)(Args...)const>
83{
84 using is_noexcept = std::true_type;
85};
86
87template<typename Ret, typename Class, typename... Args>
88struct function_type_reflection<Ret(Class::*)(Args...) volatile noexcept> : function_type_reflection<Ret(Class::*)(Args...)volatile>
89{
90 using is_noexcept = std::true_type;
91};
92
93template<typename Ret, typename Class, typename... Args>
94struct function_type_reflection<Ret(Class::*)(Args...) const volatile noexcept> : function_type_reflection<Ret(Class::*)(Args...)const volatile>
95{
96 using is_noexcept = std::true_type;
97};
98
99template<typename ... Args> concept function_type_reflectable = function_type_reflection<Args...>::exists::value;
100
101template<auto f> concept function_reflectable = function_type_reflectable<std::decay_t<decltype(f)>>;
102
103template<auto f>
106: function_type_reflection<std::decay_t<decltype(f)>>
107{
108 using parent_reflection = function_type_reflection<std::decay_t<decltype(f)>>; // for tests
109};
110
113}
Definition sygac-functions.hpp:101
Definition sygac-functions.hpp:99
A trivial type list struct for carrying function argument type lists.
Definition sygac-functions.hpp:24
Definition sygac-functions.hpp:107
Definition sygac-functions.hpp:28