File tree Expand file tree Collapse file tree 3 files changed +47
-5
lines changed Expand file tree Collapse file tree 3 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ name: Format
2
2
on : [push]
3
3
jobs :
4
4
format-cpp :
5
- name : 📀 Formatting
5
+ name : 📀 Formatting C++
6
6
runs-on : ubuntu-latest
7
7
steps :
8
8
# Global part
@@ -11,17 +11,17 @@ jobs:
11
11
12
12
# C++ part
13
13
- name : 🏗️ 🏃 clang-format
14
- uses : DoozyX/clang-format-lint-action@v0.17
14
+ uses : DoozyX/clang-format-lint-action@v0.20
15
15
with :
16
16
source : ./cpp
17
17
extensions : h,c,hpp,cpp
18
- clangFormatVersion : 17
18
+ clangFormatVersion : 20
19
19
20
20
formta-py :
21
21
defaults :
22
22
run :
23
23
working-directory : ./python
24
- name : 📀 Formatting
24
+ name : 📀 Formatting Python
25
25
runs-on : ubuntu-latest
26
26
steps :
27
27
- name : 🔔 Check out
Original file line number Diff line number Diff line change
1
+ // / Copyright (c) RenChu Wang - All Rights Reserved
2
+
3
+ #include < functional>
4
+ #include < iostream>
5
+ #include < string>
6
+ #include < vector>
7
+
8
+ struct A {
9
+ int a;
10
+ };
11
+
12
+ struct B {
13
+ float b;
14
+ };
15
+
16
+ struct C {
17
+ std::string c;
18
+ };
19
+
20
+ int main () {
21
+ A a{899 };
22
+ B b{935 };
23
+ C c{" song" };
24
+
25
+ // Now I'm using closure to simulate a thunk,
26
+ // which is a fat (function) pointer + data / state,
27
+ // which can be used to implement dynamic dispatch (as in Go).
28
+ std::function<int (int )> fa{[=](int num) { return a.a + num; }};
29
+
30
+ std::function<int (int )> fb{[=](int num) { return b.b * num; }};
31
+
32
+ std::function<int (int )> fc{[&](int num) { return int (c.c .size ()) - num; }};
33
+
34
+ std::vector<std::function<int (int )>> funcs{fa, fb, fc};
35
+
36
+ // Dynamic dispatching.
37
+ // This is very functional because this is similar to haskell's currying.
38
+ // Each f is essentially a thunk in STG.
39
+ for (auto && f : funcs) {
40
+ std::cout << f (1 ) << " \n " ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ authors = [
6
6
]
7
7
license = {text = " MIT" }
8
8
readme = " README.md"
9
- dynamic = [ " version " ]
9
+ version = " 0.0.0 "
10
10
requires-python = " >=3.13"
11
11
12
12
[build-system ]
You can’t perform that action at this time.
0 commit comments