-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_function.sh
35 lines (29 loc) · 874 Bytes
/
make_function.sh
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
if [ -z "$1" ]; then
exit
fi
if [ -z "$2" ]; then
exit
fi
struct=$1
func=$2
echo "template <typename T>"
echo "constexpr auto make_$struct(T x) noexcept {"
echo " return $struct<T>(x);"
echo "}"
echo "template <typename T>"
echo "struct $struct : function_expression<$struct<T>> {"
echo " using function_expression<$struct>::derive;"
echo " friend struct function_expression<$struct<T>>;"
echo " [[no_unique_address]] T arg;"
echo " constexpr explicit $struct(T x) noexcept : arg(x) {}"
echo " template <typename... Ts>"
echo " constexpr double operator()(Ts... xs) const noexcept {"
echo " return std::$func(arg(xs...));"
echo " }"
echo "private:"
echo " constexpr auto derive_outer() const noexcept { return /*TODO*/ arg; }"
echo "};"
echo "template <typename T>"
echo "constexpr auto $func(T x) noexcept {"
echo " return make_$struct(x);"
echo "}"