Skip to content

Commit 5b830fe

Browse files
authored
Merge pull request #60 from beman-project/clang-format
clang-formated the code
2 parents 9cb22d8 + d858f88 commit 5b830fe

File tree

227 files changed

+8815
-11854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+8815
-11854
lines changed

examples/allocator.cpp

Lines changed: 55 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -8,94 +8,69 @@
88

99
namespace ex = beman::execution26;
1010

11-
namespace
12-
{
13-
template <std::size_t Size>
14-
struct inline_resource
15-
: std::pmr::memory_resource
16-
{
17-
char const* name;
18-
inline_resource(char const* name): name(name) {}
19-
std::byte buffer[Size];
20-
std::byte* next{+this->buffer};
11+
namespace {
12+
template <std::size_t Size>
13+
struct inline_resource : std::pmr::memory_resource {
14+
const char* name;
15+
inline_resource(const char* name) : name(name) {}
16+
std::byte buffer[Size];
17+
std::byte* next{+this->buffer};
2118

22-
void* do_allocate(std::size_t size, std::size_t) override {
23-
std::cout << "allocating from=" << this->name << ", size=" << size << "\n";
24-
if (size <= std::size_t(std::distance(next, std::end(buffer)))) {
25-
std::byte* rc{this->next};
26-
this->next += size;
27-
return rc;
28-
}
29-
return nullptr;
19+
void* do_allocate(std::size_t size, std::size_t) override {
20+
std::cout << "allocating from=" << this->name << ", size=" << size << "\n";
21+
if (size <= std::size_t(std::distance(next, std::end(buffer)))) {
22+
std::byte* rc{this->next};
23+
this->next += size;
24+
return rc;
3025
}
31-
void do_deallocate(void*, std::size_t, std::size_t) override {
32-
}
33-
bool do_is_equal(std::pmr::memory_resource const& other) const noexcept override {
34-
return this == &other;
35-
}
36-
};
26+
return nullptr;
27+
}
28+
void do_deallocate(void*, std::size_t, std::size_t) override {}
29+
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override { return this == &other; }
30+
};
3731

38-
template <typename Fun>
39-
struct allocator_aware_fun
40-
{
41-
using allocator_type = std::pmr::polymorphic_allocator<>;
32+
template <typename Fun>
33+
struct allocator_aware_fun {
34+
using allocator_type = std::pmr::polymorphic_allocator<>;
4235

43-
std::remove_cvref_t<Fun> fun;
44-
allocator_type allocator{};
36+
std::remove_cvref_t<Fun> fun;
37+
allocator_type allocator{};
4538

46-
template <typename F>
47-
requires std::same_as<std::remove_cvref_t<F>, std::remove_cvref_t<Fun>>
48-
allocator_aware_fun(F&& fun): fun(std::forward<F>(fun)) {}
49-
allocator_aware_fun(allocator_aware_fun const& other, allocator_type allocator = {})
50-
: fun(other.fun)
51-
, allocator(allocator)
52-
{
53-
}
54-
allocator_aware_fun(allocator_aware_fun&& other)
55-
: fun(std::move(other.fun))
56-
, allocator(other.allocator)
57-
{
58-
}
59-
allocator_aware_fun(allocator_aware_fun&& other, allocator_type allocator)
60-
: fun(std::move(other.fun))
61-
, allocator(allocator)
62-
{
63-
}
39+
template <typename F>
40+
requires std::same_as<std::remove_cvref_t<F>, std::remove_cvref_t<Fun>>
41+
allocator_aware_fun(F&& fun) : fun(std::forward<F>(fun)) {}
42+
allocator_aware_fun(const allocator_aware_fun& other, allocator_type allocator = {})
43+
: fun(other.fun), allocator(allocator) {}
44+
allocator_aware_fun(allocator_aware_fun&& other) : fun(std::move(other.fun)), allocator(other.allocator) {}
45+
allocator_aware_fun(allocator_aware_fun&& other, allocator_type allocator)
46+
: fun(std::move(other.fun)), allocator(allocator) {}
6447

65-
template <typename... Args>
66-
auto operator()(Args&&... args) noexcept
67-
{
68-
return this->fun(this->allocator, std::forward<Args>(args)...);
69-
}
70-
};
71-
template <typename Fun>
72-
allocator_aware_fun(Fun&& fun) -> allocator_aware_fun<Fun>;
48+
template <typename... Args>
49+
auto operator()(Args&&... args) noexcept {
50+
return this->fun(this->allocator, std::forward<Args>(args)...);
51+
}
52+
};
53+
template <typename Fun>
54+
allocator_aware_fun(Fun&& fun) -> allocator_aware_fun<Fun>;
7355

74-
struct allocator_env
75-
{
76-
std::pmr::polymorphic_allocator<> allocator{};
77-
auto query(ex::get_allocator_t) const noexcept -> std::pmr::polymorphic_allocator<> {
78-
return this->allocator;
79-
}
80-
};
81-
}
56+
struct allocator_env {
57+
std::pmr::polymorphic_allocator<> allocator{};
58+
auto query(ex::get_allocator_t) const noexcept -> std::pmr::polymorphic_allocator<> { return this->allocator; }
59+
};
60+
} // namespace
8261

83-
auto main() -> int
84-
{
85-
int values[] = { 1, 2, 3 };
86-
auto s{
87-
ex::just(std::span(values))
88-
| ex::let_value(allocator_aware_fun([](auto alloc, std::span<int> v){
89-
return ex::just(std::pmr::vector<int>(v.begin(), v.end(), alloc));
90-
}))
91-
| ex::then([](auto&& v) noexcept {
92-
for (auto x: v){ std::cout << x << ", "; }
93-
std::cout << "\n";
94-
})
95-
};
62+
auto main() -> int {
63+
int values[] = {1, 2, 3};
64+
auto s{ex::just(std::span(values)) | ex::let_value(allocator_aware_fun([](auto alloc, std::span<int> v) {
65+
return ex::just(std::pmr::vector<int>(v.begin(), v.end(), alloc));
66+
})) |
67+
ex::then([](auto&& v) noexcept {
68+
for (auto x : v) {
69+
std::cout << x << ", ";
70+
}
71+
std::cout << "\n";
72+
})};
9673

9774
inline_resource<1024> state_resource("state");
98-
ex::sync_wait(
99-
ex::detail::write_env(std::move(s), allocator_env{&state_resource})
100-
);
75+
ex::sync_wait(ex::detail::write_env(std::move(s), allocator_env{&state_resource}));
10176
}

examples/stop_token.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,63 +46,53 @@ namespace exec = beman::execution26;
4646
// - std::print isn't available everywhere, yet. Let's try a simple
4747
// placeholder.
4848
static ::std::mutex io_lock;
49-
void print(std::string_view text, auto&&...)
50-
{
51-
std::lock_guard guard(io_lock);
49+
void print(std::string_view text, auto&&...) {
50+
std::lock_guard guard(io_lock);
5251
::std::cout << text;
5352
}
5453

5554
template <typename Token>
56-
auto active(Token token) -> void
57-
{
55+
auto active(Token token) -> void {
5856
auto i{0ull};
59-
while (not token.stop_requested())
60-
{
57+
while (not token.stop_requested()) {
6158
// do work
6259
++i;
6360
}
64-
print("active thread done: {}\n" , i);
61+
print("active thread done: {}\n", i);
6562
}
6663

6764
template <typename Token, typename Callback>
68-
struct stop_callback_for_t
69-
{
65+
struct stop_callback_for_t {
7066
exec::stop_callback_for_t<Token, Callback> cb;
71-
stop_callback_for_t(Token const& token, Callback callback)
72-
: cb(token, callback)
73-
{
74-
}
67+
stop_callback_for_t(const Token& token, Callback callback) : cb(token, callback) {}
7568
};
7669

7770
#ifdef __cpp_lib_latch
7871
template <typename Token>
79-
auto inactive(Token token) -> void
80-
{
72+
auto inactive(Token token) -> void {
8173
::std::latch latch(1);
82-
stop_callback_for_t cb(token, [&latch]{ latch.count_down(); });
74+
stop_callback_for_t cb(token, [&latch] { latch.count_down(); });
8375

8476
latch.wait();
8577
print("inactive thread done (latch)\n");
8678
}
8779
#else
8880
template <typename Token>
89-
auto inactive(Token token) -> void
90-
{
81+
auto inactive(Token token) -> void {
9182
::std::condition_variable cond;
92-
stop_callback_for_t cb(token, [&cond]{ cond.notify_one(); });
83+
stop_callback_for_t cb(token, [&cond] { cond.notify_one(); });
9384

94-
::std::mutex lock;
85+
::std::mutex lock;
9586
::std::unique_lock guard(lock);
96-
cond.wait(guard, [token]{ return token.stop_requested(); });
87+
cond.wait(guard, [token] { return token.stop_requested(); });
9788
print("inactive thread done (condition_variable)\n");
9889
}
9990
#endif
10091

101-
auto main() -> int
102-
{
92+
auto main() -> int {
10393
exec::stop_source source;
104-
::std::thread act([token = source.get_token()] { active(token); });
105-
::std::thread inact([token = source.get_token()] { inactive(token); });
94+
::std::thread act([token = source.get_token()] { active(token); });
95+
::std::thread inact([token = source.get_token()] { inactive(token); });
10696

10797
print("threads started\n");
10898
source.request_stop();

examples/stopping.cpp

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
// The example shows a bit of how cancellation works:
5-
// It creates work with a sender injecting a stop token
5+
// It creates work with a sender injecting a stop token
66
// which gets started in a thread. To stop this thread
77
// the corresponding stop source is requested to stop.
88

@@ -18,34 +18,26 @@ namespace ex = beman::execution26;
1818

1919
// ----------------------------------------------------------------------------
2020

21-
struct env
22-
{
21+
struct env {
2322
ex::inplace_stop_token token;
2423

25-
env(ex::inplace_stop_token token): token(token) {}
24+
env(ex::inplace_stop_token token) : token(token) {}
2625

27-
auto query(ex::get_stop_token_t const&) const noexcept {
28-
return this->token;
29-
}
26+
auto query(const ex::get_stop_token_t&) const noexcept { return this->token; }
3027
};
3128

3229
template <typename Sender>
33-
struct inject_cancel_sender
34-
{
30+
struct inject_cancel_sender {
3531
using sender_concept = ex::sender_t;
3632

37-
3833
template <typename Receiver>
39-
struct receiver
40-
{
34+
struct receiver {
4135
using receiver_concept = ex::receiver_t;
4236

4337
std::remove_cvref_t<Receiver> inner_receiver;
4438
ex::inplace_stop_token token{};
4539

46-
auto get_env() const noexcept -> env {
47-
return {this->token};
48-
}
40+
auto get_env() const noexcept -> env { return {this->token}; }
4941

5042
template <typename... T>
5143
auto set_value(T&&... t) noexcept -> void {
@@ -55,18 +47,16 @@ struct inject_cancel_sender
5547
auto set_error(E&& e) noexcept -> void {
5648
ex::set_error(std::move(inner_receiver), std::forward<E>(e));
5749
}
58-
auto set_stopped() noexcept -> void {
59-
ex::set_stopped(std::move(inner_receiver));
60-
}
50+
auto set_stopped() noexcept -> void { ex::set_stopped(std::move(inner_receiver)); }
6151
};
6252

6353
template <typename E>
64-
auto get_completion_signatures(E const&) {
54+
auto get_completion_signatures(const E&) {
6555
return ex::get_completion_signatures(this->sender, env{ex::inplace_stop_token{}});
6656
}
6757

6858
ex::inplace_stop_token token{};
69-
Sender sender;
59+
Sender sender;
7060

7161
template <typename Receiver>
7262
auto connect(Receiver&& recv) && {
@@ -77,37 +67,29 @@ struct inject_cancel_sender
7767
template <typename S>
7868
inject_cancel_sender(ex::inplace_stop_token, S&&) -> inject_cancel_sender<std::decay_t<S>>;
7969

80-
struct receiver
81-
{
70+
struct receiver {
8271
using receiver_concept = ex::receiver_t;
8372
auto set_value(auto&&...) noexcept -> void {}
8473
auto set_error(auto&&) noexcept -> void {}
8574
auto set_stopped() noexcept -> void {}
8675
};
8776

88-
int main()
89-
{
77+
int main() {
9078
ex::inplace_stop_source source;
9179

92-
std::thread t([token=source.get_token()]{
80+
std::thread t([token = source.get_token()] {
9381
ex::sync_wait(
94-
inject_cancel_sender{token,
95-
ex::read_env(ex::get_stop_token)
96-
| ex::then([](ex::inplace_stop_token tok){
97-
while (not tok.stop_requested())
98-
{
99-
std::cout << "sleeping\n";
100-
std::this_thread::sleep_for(1s);
101-
}
102-
})
103-
});
104-
}
105-
);
82+
inject_cancel_sender{token, ex::read_env(ex::get_stop_token) | ex::then([](ex::inplace_stop_token tok) {
83+
while (not tok.stop_requested()) {
84+
std::cout << "sleeping\n";
85+
std::this_thread::sleep_for(1s);
86+
}
87+
})});
88+
});
10689

10790
std::cin.get();
10891
std::cout << "requesting stop\n";
10992
source.request_stop();
11093

11194
t.join();
11295
}
113-

0 commit comments

Comments
 (0)