Skip to content

Commit a0ef335

Browse files
committed
more c++20 fixes
1 parent eee320d commit a0ef335

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

.github/workflows/linux.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ jobs:
8686
max-size: "2G"
8787
- name: Compile
8888
run: |
89-
$CXX --version
9089
cmake -B build -G Ninja -DORYX_CRT_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release
9190
cmake --build build
9291
- name: Run tests

include/oryx/callback_list.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ template <class... Args>
1717
class CallbackList {
1818
public:
1919
using ID = uint64_t;
20+
using Callback = std::function<void(Args...)>;
2021

2122
static constexpr ID kIDMax = std::numeric_limits<ID>::max();
2223
/**
@@ -41,13 +42,11 @@ class CallbackList {
4142
ID id_;
4243
};
4344

44-
using Callback = std::function<void(Args...)>;
45-
4645
CallbackList() = default;
4746

4847
auto Subscribe(Callback&& cb) -> Handle {
4948
ID id = id_.fetch_add(1, std::memory_order_relaxed);
50-
subs_.Apply([&](auto& subs) mutable { subs.emplace_back(id, std::forward<Callback>(cb)); });
49+
subs_.Apply([&](auto& subs) { subs.emplace_back(id, std::forward<Callback>(cb)); });
5150
return Handle(id);
5251
}
5352

include/oryx/lazy_component.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ namespace oryx {
1313
template <class T>
1414
class LazyComponent {
1515
public:
16-
using FactoryContainer = std::move_only_function<T()>;
16+
#ifdef __cpp_lib_move_only_function
17+
template <typename... S>
18+
using FunctionType = std::move_only_function<S...>;
19+
#else
20+
template <typename... S>
21+
using FunctionType = std::function<S...>;
22+
#endif
23+
using FactoryContainer = FunctionType<T()>;
1724

1825
LazyComponent() = default;
1926

@@ -53,7 +60,7 @@ class LazyComponent {
5360
}
5461

5562
std::once_flag created_flag_{};
56-
std::move_only_function<T()> factory_{};
63+
FactoryContainer factory_{};
5764
mutable std::unique_ptr<T> value_{};
5865
};
5966

tests/retry_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST_CASE("Retryable succeeds after some tries") {
3636
TEST_CASE("Exhausting max retries") {
3737
int tries = 4;
3838
int tries_so_far = 0;
39-
auto retryable = [&]() -> bool {
39+
auto retryable = [&]() {
4040
tries_so_far++;
4141

4242
if (tries_so_far == tries) {
@@ -56,14 +56,14 @@ TEST_CASE("Passing a custom predicate") {
5656
int tries_so_far = 0;
5757
int tries = 5;
5858

59-
auto never_succeeds = [&] -> bool {
59+
auto never_succeeds = [&]() {
6060
if (++tries_so_far == tries) {
6161
flag = true;
6262
}
6363
return false;
6464
};
6565

66-
auto stopper = [&flag] -> bool { return flag; };
66+
auto stopper = [&flag]() { return flag; };
6767
auto config = kDefaultConfig;
6868
config.max_retries = 10;
6969
CHECK_FALSE(retry::ExponentialBackoff(config, never_succeeds, stopper));
@@ -75,7 +75,7 @@ TEST_CASE("Works with stop token as expected") {
7575
int tries_so_far = 0;
7676
int tries = 5;
7777

78-
auto never_succeeds = [&] -> bool {
78+
auto never_succeeds = [&]() {
7979
if (++tries_so_far == tries) {
8080
ssource.request_stop();
8181
}

0 commit comments

Comments
 (0)