repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
arity.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <type_traits>
4
5namespace librepr::detail {
6struct Universal {
7 template <typename T>
8 /* implicit */ constexpr operator T(); // NOLINT
9};
10
11template <typename T>
12 requires std::is_aggregate_v<T>
13struct ArityImpl {
14 template <typename... Fillers>
15 static consteval auto array_length(auto... parameters) {
16 if constexpr (requires { T{parameters..., {Fillers{}..., Universal{}}}; }) {
18 } else {
19 return sizeof...(Fillers);
20 }
21 }
22
23 static consteval auto arity_simple(auto... parameters) {
24 if constexpr (requires { T{parameters..., Universal{}}; }) {
25 return arity_simple(parameters..., Universal{});
26 } else {
27 return sizeof...(parameters);
28 }
29 }
30
31 template <typename... Trails>
32 static consteval auto arity_simple_ag(auto... parameters) {
33 if constexpr (requires { T{parameters..., {Universal{}, Universal{}}, Trails{}..., Universal{}}; }) {
35 } else {
36 return sizeof...(parameters) + sizeof...(Trails) + 1;
37 }
38 }
39
40 static consteval auto arity(std::size_t minus = 0, auto... parameters) {
41 if constexpr (requires { T{parameters..., {Universal{}, Universal{}}}; }) {
42 if constexpr (arity_simple_ag(parameters...) != arity_simple(parameters...)) {
43 minus += array_length(parameters...) - 1;
44 }
45
46 return arity(minus, parameters..., Universal{});
47 } else if constexpr (requires { T{parameters..., Universal{}}; }) {
48 return arity(minus, parameters..., Universal{});
49 } else {
50 return sizeof...(parameters) - minus;
51 }
52 }
53};
54
55template <typename T>
56 requires std::is_aggregate_v<T>
58
59} // namespace librepr::detail
Definition assert.h:89
constexpr std::size_t arity
Definition arity.h:57
std::string code_for()
Definition repr:39
Definition arity.h:13
static consteval auto array_length(auto... parameters)
Definition arity.h:15
static consteval auto arity(std::size_t minus=0, auto... parameters)
Definition arity.h:40
static consteval auto arity_simple(auto... parameters)
Definition arity.h:23
static consteval auto arity_simple_ag(auto... parameters)
Definition arity.h:32
Definition arity.h:6