Iros
 
Loading...
Searching...
No Matches
function.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/meta/core.h"
5
6namespace di::concepts {
7template<template<typename...> typename Fun, typename... Args>
8concept ValidInstantiation = requires { typename Fun<Args...>; };
9}
10
11namespace di::meta {
12namespace detail {
13 template<template<typename...> typename, typename...>
14 struct DeferHelper {};
15
16#pragma GCC diagnostic push
17#ifdef DI_GCC
18#pragma GCC diagnostic ignored "-Wsubobject-linkage"
19#endif
20 template<template<typename...> typename Fun, typename... Args>
21 requires(concepts::ValidInstantiation<Fun, Args...>)
22 struct DeferHelper<Fun, Args...> : TypeConstant<Fun<Args...>> {};
23#pragma GCC diagnostic pop
24}
25
26template<template<typename...> typename Fun, typename... Args>
27using Defer = detail::DeferHelper<Fun, Args...>;
28
29template<template<typename...> typename Fun>
30struct Quote {
31 template<typename... Args>
32 using Invoke = typename Defer<Fun, Args...>::Type;
33};
34}
35
36namespace di::concepts {
37template<typename T>
38concept MetaInvocable = requires { typename meta::Quote<T::template Invoke>; };
39}
40
41namespace di::meta {
42template<concepts::MetaInvocable Fun, typename... Args>
43using Invoke = Type<Defer<Fun::template Invoke, Args...>>;
44
45namespace detail {
46 template<typename F, typename T>
48
49 template<typename F, typename... Args>
50 requires(concepts::ValidInstantiation<Invoke, F, Args...>)
51 struct ApplyHelper<F, List<Args...>> : TypeConstant<Invoke<F, Args...>> {};
52}
53
54template<concepts::MetaInvocable F, concepts::TypeList T>
56
57template<concepts::MetaInvocable Fun>
58struct Uncurry {
59 template<concepts::TypeList List>
61};
62
63template<concepts::MetaInvocable MetaFn, typename... Bound>
64struct BindFront {
65 template<typename... Rest>
66 using Invoke = meta::Invoke<MetaFn, Bound..., Rest...>;
67};
68
69template<concepts::MetaInvocable MetaFn, typename... Bound>
70struct BindBack {
71 template<typename... Rest>
72 using Invoke = meta::Invoke<MetaFn, Rest..., Bound...>;
73};
74
75template<concepts::MetaInvocable MetaFn>
76struct Flip {
77 template<typename T, typename U>
79};
80
81namespace detail {
82 template<typename...>
84
85 template<concepts::MetaInvocable F>
86 struct ComposeHelper<F> : F {};
87
88 template<concepts::MetaInvocable F, concepts::MetaInvocable G>
90 template<typename... Args>
91 using Invoke = meta::Invoke<F, meta::Invoke<G, Args...>>;
92 };
93
95 struct ComposeHelper<F, Gs...> : ComposeHelper<F, ComposeHelper<Gs...>> {};
96}
97
98template<concepts::MetaInvocable... Funs>
100
101namespace detail {
102 template<typename...>
104
105 template<concepts::MetaInvocable F>
106 struct ChainHelper<F> : F {};
107
108 template<concepts::MetaInvocable F, concepts::MetaInvocable G>
110 template<typename... Args>
111 using Invoke = meta::Invoke<G, meta::Invoke<F, Args...>>;
112 };
113
115 struct ChainHelper<F, Gs...> : ChainHelper<F, ChainHelper<Gs...>> {};
116}
117
118template<concepts::MetaInvocable... Funs>
119using Chain = detail::ChainHelper<Funs...>;
120
121template<typename T>
122struct SameAs {
123 template<typename... Args>
125};
126
127template<concepts::MetaInvocable MetaFn>
128struct Not {
129 template<typename... Args>
130 using Invoke = Constexpr<!meta::Invoke<MetaFn, Args...>::value>;
131};
132}
Definition function.h:38
Definition core.h:114
Definition function.h:8
Definition any_storable.h:9
Definition json_deserializer.h:532
Definition const_sentinel.h:8
Definition merge_interfaces.h:6
detail::ChainHelper< Funs... > Chain
Definition function.h:119
T::Type Type
Definition core.h:26
detail::ComposeHelper< Funs... > Compose
Definition function.h:99
Type< detail::ApplyHelper< F, T > > Apply
Definition function.h:55
detail::DeferHelper< Fun, Args... > Defer
Definition function.h:27
Type< Defer< Fun::template Invoke, Args... > > Invoke
Definition function.h:43
Definition function.h:70
meta::Invoke< MetaFn, Rest..., Bound... > Invoke
Definition function.h:72
Definition function.h:64
meta::Invoke< MetaFn, Bound..., Rest... > Invoke
Definition function.h:66
A wrapper for a constexpr value.
Definition core.h:77
Definition function.h:76
meta::Invoke< MetaFn, U, T > Invoke
Definition function.h:78
Definition core.h:5
Definition function.h:128
Constexpr<!meta::Invoke< MetaFn, Args... >::value > Invoke
Definition function.h:130
Definition function.h:30
typename Defer< Fun, Args... >::Type Invoke
Definition function.h:32
Definition function.h:122
Constexpr<(concepts::SameAs< T, Args > &&...)> Invoke
Definition function.h:124
Definition core.h:18
Definition function.h:58
Apply< Fun, List > Invoke
Definition function.h:60
Definition function.h:47
Definition function.h:103
meta::Invoke< G, meta::Invoke< F, Args... > > Invoke
Definition function.h:111
Definition function.h:83
meta::Invoke< F, meta::Invoke< G, Args... > > Invoke
Definition function.h:91
Definition function.h:14