Skip to content

Commit e20c068

Browse files
committed
Merge branch 'main' into quadrature_encoder
2 parents 3566d1c + 61313f0 commit e20c068

File tree

3 files changed

+107
-8
lines changed

3 files changed

+107
-8
lines changed

.github/workflows/c-cpp.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ jobs:
1111
build:
1212
strategy:
1313
matrix:
14-
os: [ubuntu-22.04]
15-
cxx: [g++-12, g++-11, clang++-15, clang++-14]
14+
os: [ubuntu-22.04, ubuntu-24.04]
15+
cxx: [g++-14, g++-13, g++-12, g++-11, clang++-18, clang++-17, clang++-16, clang++-15 ]
1616
include:
1717
- os: macos-latest
1818
cxx: clang++
19-
- os: ubuntu-24.04
20-
cxx: g++-13
21-
- os: ubuntu-24.04
19+
exclude:
20+
- os: ubuntu-22.04
2221
cxx: clang++-16
23-
- os: ubuntu-24.04
22+
- os: ubuntu-22.04
2423
cxx: clang++-17
25-
- os: ubuntu-24.04
24+
- os: ubuntu-22.04
2625
cxx: clang++-18
26+
- os: ubuntu-22.04
27+
cxx: g++-13
28+
- os: ubuntu-22.04
29+
cxx: g++-14
30+
31+
- os: ubuntu-24.04
32+
cxx: clang++-15
33+
- os: ubuntu-24.04
34+
cxx: g++-11
2735

2836
runs-on: ${{ matrix.os }}
2937

tests/callable_tests.cc

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,91 @@ TEST_CASE("Callable Function lots of params") {
4848
CHECK(func(10, 10.f, 'a', {}, {2, 'a', 1.2f, 1.4}) == 137);
4949
CHECK(capture == 20);
5050
}
51+
52+
TEST_CASE("FunctionSized") {
53+
// This fails to compile (which is what we want)
54+
// auto capture{0};
55+
// auto capture2{0};
56+
// auto capture3{0};
57+
// auto func = Function<int(int, int)>{[&](int a, int b) {
58+
// capture += 10;
59+
// capture2 += 10;
60+
// capture3 += 10;
61+
// return a + b + capture;
62+
// }};
63+
64+
auto capture{0};
65+
auto capture2{0};
66+
auto capture3{0};
67+
auto func = FunctionSized<sizeof(void *) * 3, int(int, int)>{[&](int a, int b) {
68+
capture += 10;
69+
capture2 += 10;
70+
capture3 += 10;
71+
return a + b + capture;
72+
}};
73+
}
74+
75+
TEST_CASE("Callable") {
76+
auto capture{0};
77+
78+
auto func = Callback{[&capture] {
79+
capture += 10;
80+
return capture;
81+
}};
82+
83+
func();
84+
CHECK(capture == 10);
85+
func();
86+
CHECK(capture == 20);
87+
}
88+
89+
TEST_CASE("CallableSized") {
90+
auto capture{0};
91+
auto capture2{0};
92+
auto capture3{0};
93+
94+
auto func = CallbackSized<sizeof(void *) * 3>{[&] {
95+
capture += 10;
96+
capture2 += 10;
97+
capture3 += 10;
98+
return capture;
99+
}};
100+
101+
func();
102+
CHECK(capture3 == 10);
103+
func();
104+
CHECK(capture3 == 20);
105+
}
106+
107+
TEST_CASE("~Callable") {
108+
auto capture{0};
109+
110+
Callback *func = new Callback{[&capture] {
111+
capture += 10;
112+
return capture;
113+
}};
114+
115+
(*func)();
116+
CHECK(capture == 10);
117+
(*func)();
118+
CHECK(capture == 20);
119+
120+
delete func;
121+
122+
Callback *empty = new Callback();
123+
delete empty;
124+
}
125+
126+
TEST_CASE("operator bool") {
127+
auto capture{0};
128+
129+
Callback func;
130+
CHECK_FALSE((bool)func);
131+
132+
func = Callback{[&capture] {
133+
capture += 10;
134+
return capture;
135+
}};
136+
137+
CHECK((bool)func);
138+
}

util/callable.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ private:
5151
template<typename Callable>
5252
static Ret invoke(void *object, Args... args) {
5353
Callable &callable = *reinterpret_cast<Callable *>(object);
54-
return callable(std::forward<Args>(args)...);
54+
if constexpr (std::is_same_v<void, Ret>)
55+
callable(std::forward<Args>(args)...);
56+
else
57+
return callable(std::forward<Args>(args)...);
5558
}
5659

5760
template<typename Callable>

0 commit comments

Comments
 (0)