- Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathfunctions.h
58 lines (51 loc) · 1.39 KB
/
functions.h
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
///////////////////////////////////////////////////////////////////////////////
//
// Module : functions.h
// Copyright : (c) Andy Arvanitis 2019
// License : BSD
//
// Maintainer : Andy Arvanitis
// Stability : experimental
// Portability :
//
// Runtime function types (for regular functions and lambdas)
//
///////////////////////////////////////////////////////////////////////////////
//
#ifndef purescript_functions_H
#definepurescript_functions_H
namespacepurescript {
namespace_template_ {
template <typename T>
classfn_t {
public:
virtual~fn_t() {}
virtualautooperator ()(const T&) const -> T = 0;
};
template <typename T, typename U>
classfn_T : publicfn_t<T> {
U fn;
public:
fn_T(U&& f) noexcept : fn(std::move(f)) {}
autooperator ()(const T& arg) const -> T override {
returnfn(arg);
}
};
template <typename T>
classeff_fn_t {
public:
virtual~eff_fn_t() {}
virtualautooperator ()() const -> T = 0;
};
template <typename T, typename U>
classeff_fn_T : publiceff_fn_t<T> {
U fn;
public:
eff_fn_T(U&& f) noexcept : fn(std::move(f)) {}
autooperator ()() const -> T override {
returnfn();
}
};
} // namespace _template_
} // namespace purescript
#endif// purescript_functions_H