diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 3d59ec1b6..a0b3ec9d5 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -33,3 +33,4 @@ aee392a046a26ae2340849fe98e38332d9537397 # new formatting style for improved readability 0cccd586b8d75c64b289e38f334e95846dfb4f33 +72666721b5787c1adcc100dd86c26fbbe8bda82f diff --git a/examples/benchmark/asio_thread_pool.cpp b/examples/benchmark/asio_thread_pool.cpp index 3d6dae57b..ef693fe9f 100644 --- a/examples/benchmark/asio_thread_pool.cpp +++ b/examples/benchmark/asio_thread_pool.cpp @@ -18,7 +18,8 @@ #include #include -struct RunThread { +struct RunThread +{ void operator()(exec::asio::asio_thread_pool& pool, std::size_t total_scheds, std::size_t tid, @@ -27,49 +28,62 @@ struct RunThread { std::span buffer, #endif std::atomic& stop, - exec::numa_policy numa) { + exec::numa_policy numa) + { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); - auto scheduler = pool.get_scheduler(); - std::mutex mut; + auto scheduler = pool.get_scheduler(); + std::mutex mut; std::condition_variable cv; - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - pmr::monotonic_buffer_resource resource{ - buffer.data(), buffer.size(), pmr::null_memory_resource()}; + pmr::monotonic_buffer_resource resource{buffer.data(), + buffer.size(), + pmr::null_memory_resource()}; pmr::polymorphic_allocator alloc(&resource); auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - auto env = stdexec::prop{stdexec::get_allocator, alloc}; - while (scheds) { - exec::start_detached( - stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - }), - env); + auto env = stdexec::prop{stdexec::get_allocator, alloc}; + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + }), + env); --scheds; } #else auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - while (scheds) { - exec::start_detached(stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - })); + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + })); --scheds; } #endif @@ -81,6 +95,7 @@ struct RunThread { } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ my_main(argc, argv); } diff --git a/examples/benchmark/fibonacci.cpp b/examples/benchmark/fibonacci.cpp index 14fa101f7..c6be63ee9 100644 --- a/examples/benchmark/fibonacci.cpp +++ b/examples/benchmark/fibonacci.cpp @@ -24,7 +24,8 @@ #include #include -auto serial_fib(long n) -> long { +auto serial_fib(long n) -> long +{ return n < 2 ? n : serial_fib(n - 1) + serial_fib(n - 2); } @@ -35,41 +36,48 @@ using any_sender_of = using fib_sender = any_sender_of; template -struct fib_s { - using sender_concept = stdexec::sender_t; +struct fib_s +{ + using sender_concept = stdexec::sender_t; using completion_signatures = stdexec::completion_signatures; - long cutoff; - long n; + long cutoff; + long n; Scheduler sched; template - struct operation { - Receiver rcvr_; - long cutoff; - long n; + struct operation + { + Receiver rcvr_; + long cutoff; + long n; Scheduler sched; - void start() & noexcept { - if (n < cutoff) { + void start() & noexcept + { + if (n < cutoff) + { stdexec::set_value(static_cast(rcvr_), serial_fib(n)); - } else { - auto mkchild = [&](long n) { + } + else + { + auto mkchild = [&](long n) + { return stdexec::starts_on(sched, fib_sender(fib_s{cutoff, n, sched})); }; exec::start_detached( stdexec::when_all(mkchild(n - 1), mkchild(n - 2)) - | stdexec::then([rcvr = static_cast(rcvr_)](long a, long b) mutable { - stdexec::set_value(static_cast(rcvr), a + b); - })); + | stdexec::then([rcvr = static_cast(rcvr_)](long a, long b) mutable + { stdexec::set_value(static_cast(rcvr), a + b); })); } } }; template Receiver> [[nodiscard]] - auto connect(Receiver rcvr) const -> operation { + auto connect(Receiver rcvr) const -> operation + { return {static_cast(rcvr), cutoff, n, sched}; } }; @@ -78,14 +86,17 @@ template fib_s(long cutoff, long n, Scheduler sched) -> fib_s; template -auto measure(F&& f) { +auto measure(F&& f) +{ std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); f(); return std::chrono::duration_cast(std::chrono::steady_clock::now() - start).count(); } -auto main(int argc, char** argv) -> int { - if (argc < 5) { +auto main(int argc, char** argv) -> int +{ + if (argc < 5) + { std::cerr << "Usage: example.benchmark.fibonacci cutoff n nruns {tbb|static}" << std::endl; return -1; } @@ -93,29 +104,36 @@ auto main(int argc, char** argv) -> int { // skip 'warmup' iterations for performance measurements static constexpr size_t warmup = 1; - long cutoff = std::strtol(argv[1], nullptr, 10); - long n = std::strtol(argv[2], nullptr, 10); - std::size_t nruns = std::strtoul(argv[3], nullptr, 10); + long cutoff = std::strtol(argv[1], nullptr, 10); + long n = std::strtol(argv[2], nullptr, 10); + std::size_t nruns = std::strtoul(argv[3], nullptr, 10); - if (nruns <= warmup) { + if (nruns <= warmup) + { std::cerr << "nruns should be >= " << warmup << std::endl; return -1; } std::variant pool; - if (argv[4] == std::string_view("tbb")) { + if (argv[4] == std::string_view("tbb")) + { pool.emplace(static_cast(std::thread::hardware_concurrency())); - } else { - pool.emplace( - std::thread::hardware_concurrency(), exec::bwos_params{}, exec::get_numa_policy()); + } + else + { + pool.emplace(std::thread::hardware_concurrency(), + exec::bwos_params{}, + exec::get_numa_policy()); } std::vector times; - long result; - for (unsigned long i = 0; i < nruns; ++i) { - auto snd = std::visit( - [&](auto&& pool) { return fib_sender(fib_s{cutoff, n, pool.get_scheduler()}); }, pool); + long result; + for (unsigned long i = 0; i < nruns; ++i) + { + auto snd = std::visit([&](auto&& pool) + { return fib_sender(fib_s{cutoff, n, pool.get_scheduler()}); }, + pool); auto time = measure( [&] { std::tie(result) = stdexec::sync_wait(std::move(snd)).value(); }); diff --git a/examples/benchmark/static_thread_pool.cpp b/examples/benchmark/static_thread_pool.cpp index 6eca77a0a..9ffbb2480 100644 --- a/examples/benchmark/static_thread_pool.cpp +++ b/examples/benchmark/static_thread_pool.cpp @@ -18,61 +18,74 @@ #include #include -struct RunThread { - void operator()( - exec::static_thread_pool& pool, - std::size_t total_scheds, - std::size_t tid, - std::barrier<>& barrier, +struct RunThread +{ + void operator()(exec::static_thread_pool& pool, + std::size_t total_scheds, + std::size_t tid, + std::barrier<>& barrier, #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - std::span buffer, + std::span buffer, #endif - std::atomic& stop, - exec::numa_policy numa) { + std::atomic& stop, + exec::numa_policy numa) + { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); exec::nodemask mask{}; mask.set(static_cast(numa_node)); - auto scheduler = pool.get_constrained_scheduler(&mask); - std::mutex mut; + auto scheduler = pool.get_constrained_scheduler(&mask); + std::mutex mut; std::condition_variable cv; - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - pmr::monotonic_buffer_resource resource{ - buffer.data(), buffer.size(), pmr::null_memory_resource()}; + pmr::monotonic_buffer_resource resource{buffer.data(), + buffer.size(), + pmr::null_memory_resource()}; pmr::polymorphic_allocator alloc(&resource); auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - auto env = stdexec::prop{stdexec::get_allocator, alloc}; - while (scheds) { - exec::start_detached( - stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - }), - env); + auto env = stdexec::prop{stdexec::get_allocator, alloc}; + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + }), + env); --scheds; } #else auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - while (scheds) { - exec::start_detached(stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - })); + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + })); --scheds; } #endif @@ -84,14 +97,17 @@ struct RunThread { } }; -struct my_numa_distribution : public exec::default_numa_policy { +struct my_numa_distribution : public exec::default_numa_policy +{ [[nodiscard]] - auto thread_index_to_node(std::size_t index) const noexcept -> int { + auto thread_index_to_node(std::size_t index) const noexcept -> int + { return exec::default_numa_policy::thread_index_to_node(2 * index); } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ my_numa_distribution numa{}; my_main(argc, argv, numa); } \ No newline at end of file diff --git a/examples/benchmark/static_thread_pool_bulk_enqueue.cpp b/examples/benchmark/static_thread_pool_bulk_enqueue.cpp index 778cf04bd..297cd7e7d 100644 --- a/examples/benchmark/static_thread_pool_bulk_enqueue.cpp +++ b/examples/benchmark/static_thread_pool_bulk_enqueue.cpp @@ -21,34 +21,37 @@ # include # include -struct RunThread { - void operator()( - exec::static_thread_pool& pool, - std::size_t total_scheds, - std::size_t tid, - std::barrier<>& barrier, +struct RunThread +{ + void operator()(exec::static_thread_pool& pool, + std::size_t total_scheds, + std::size_t tid, + std::barrier<>& barrier, # ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - std::span buffer, + std::span buffer, # endif - std::atomic& stop, - exec::numa_policy numa) { + std::atomic& stop, + exec::numa_policy numa) + { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } # ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - pmr::monotonic_buffer_resource rsrc{buffer.data(), buffer.size()}; + pmr::monotonic_buffer_resource rsrc{buffer.data(), buffer.size()}; pmr::polymorphic_allocator alloc{&rsrc}; - auto env = stdexec::prop{stdexec::get_allocator, alloc}; + auto env = stdexec::prop{stdexec::get_allocator, alloc}; auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - auto iterate = exec::schedule_all(pool, std::views::iota(start, end)) + auto iterate = exec::schedule_all(pool, std::views::iota(start, end)) | exec::ignore_all_values() | stdexec::write_env(env); # else auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - auto iterate = exec::schedule_all(pool, std::views::iota(start, end)) + auto iterate = exec::schedule_all(pool, std::views::iota(start, end)) | exec::ignore_all_values(); # endif stdexec::sync_wait(iterate); @@ -57,18 +60,20 @@ struct RunThread { } }; -struct my_numa_distribution : public exec::default_numa_policy { +struct my_numa_distribution : public exec::default_numa_policy +{ [[nodiscard]] - auto thread_index_to_node(std::size_t index) const noexcept -> int { + auto thread_index_to_node(std::size_t index) const noexcept -> int + { return exec::default_numa_policy::thread_index_to_node(2 * index); } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ exec::numa_policy numa{my_numa_distribution{}}; my_main(argc, argv, std::move(numa)); } #else -int main() { -} +int main() {} #endif \ No newline at end of file diff --git a/examples/benchmark/static_thread_pool_bulk_enqueue_nested.cpp b/examples/benchmark/static_thread_pool_bulk_enqueue_nested.cpp index 2d3265587..b6927f816 100644 --- a/examples/benchmark/static_thread_pool_bulk_enqueue_nested.cpp +++ b/examples/benchmark/static_thread_pool_bulk_enqueue_nested.cpp @@ -21,35 +21,38 @@ # include # include -struct RunThread { - void operator()( - exec::static_thread_pool& pool, - std::size_t total_scheds, - std::size_t tid, - std::barrier<>& barrier, +struct RunThread +{ + void operator()(exec::static_thread_pool& pool, + std::size_t total_scheds, + std::size_t tid, + std::barrier<>& barrier, # ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - std::span buffer, + std::span buffer, # endif - std::atomic& stop, - exec::numa_policy numa) { + std::atomic& stop, + exec::numa_policy numa) + { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); auto scheduler = pool.get_scheduler_on_thread(tid); - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } # ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - pmr::monotonic_buffer_resource rsrc{buffer.data(), buffer.size()}; + pmr::monotonic_buffer_resource rsrc{buffer.data(), buffer.size()}; pmr::polymorphic_allocator alloc{&rsrc}; - auto env = stdexec::prop{stdexec::get_allocator, alloc}; + auto env = stdexec::prop{stdexec::get_allocator, alloc}; auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - auto iterate = exec::iterate(std::views::iota(start, end)) | exec::ignore_all_values() + auto iterate = exec::iterate(std::views::iota(start, end)) | exec::ignore_all_values() | stdexec::write_env(env); # else auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - auto iterate = exec::iterate(std::views::iota(start, end)) | exec::ignore_all_values(); + auto iterate = exec::iterate(std::views::iota(start, end)) | exec::ignore_all_values(); # endif stdexec::sync_wait(stdexec::starts_on(scheduler, iterate)); barrier.arrive_and_wait(); @@ -57,10 +60,10 @@ struct RunThread { } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ my_main(argc, argv); } #else -int main() { -} +int main() {} #endif \ No newline at end of file diff --git a/examples/benchmark/static_thread_pool_nested.cpp b/examples/benchmark/static_thread_pool_nested.cpp index f4a7028a1..8e08218fb 100644 --- a/examples/benchmark/static_thread_pool_nested.cpp +++ b/examples/benchmark/static_thread_pool_nested.cpp @@ -18,68 +18,86 @@ #include #include -struct RunThread { - void operator()( - exec::static_thread_pool& pool, - std::size_t total_scheds, - std::size_t tid, - std::barrier<>& barrier, +struct RunThread +{ + void operator()(exec::static_thread_pool& pool, + std::size_t total_scheds, + std::size_t tid, + std::barrier<>& barrier, #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - std::span buffer, + std::span buffer, #endif - std::atomic& stop, - exec::numa_policy numa) { + std::atomic& stop, + exec::numa_policy numa) + { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); - auto scheduler = pool.get_scheduler(); - std::mutex mut; + auto scheduler = pool.get_scheduler(); + std::mutex mut; std::condition_variable cv; - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - pmr::monotonic_buffer_resource resource{ - buffer.data(), buffer.size(), pmr::null_memory_resource()}; + pmr::monotonic_buffer_resource resource{buffer.data(), + buffer.size(), + pmr::null_memory_resource()}; pmr::polymorphic_allocator alloc(&resource); auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - auto env = stdexec::prop{stdexec::get_allocator, alloc}; - stdexec::sync_wait(stdexec::schedule(scheduler) | stdexec::then([&] { - auto nested_scheduler = pool.get_scheduler(); - while (scheds) { - exec::start_detached( - stdexec::schedule(nested_scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - }), - env); - --scheds; - } - })); + auto env = stdexec::prop{stdexec::get_allocator, alloc}; + stdexec::sync_wait(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto nested_scheduler = pool.get_scheduler(); + while (scheds) + { + exec::start_detached(stdexec::schedule(nested_scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + }), + env); + --scheds; + } + })); #else auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - stdexec::sync_wait(stdexec::schedule(scheduler) | stdexec::then([&] { - auto nested_scheduler = pool.get_scheduler(); - while (scheds) { - exec::start_detached( - stdexec::schedule(nested_scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - })); - --scheds; - } - })); + stdexec::sync_wait(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto nested_scheduler = pool.get_scheduler(); + while (scheds) + { + exec::start_detached(stdexec::schedule(nested_scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + })); + --scheds; + } + })); #endif std::unique_lock lock{mut}; cv.wait(lock, [&] { return counter.load() == 0; }); @@ -89,6 +107,7 @@ struct RunThread { } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ my_main(argc, argv); } \ No newline at end of file diff --git a/examples/benchmark/taskflow_thread_pool.cpp b/examples/benchmark/taskflow_thread_pool.cpp index 2c9ed9c58..10db91980 100644 --- a/examples/benchmark/taskflow_thread_pool.cpp +++ b/examples/benchmark/taskflow_thread_pool.cpp @@ -18,59 +18,72 @@ #include #include -struct RunThread { - void operator()( - exec::taskflow::taskflow_thread_pool& pool, - std::size_t total_scheds, - std::size_t tid, - std::barrier<>& barrier, +struct RunThread +{ + void operator()(exec::taskflow::taskflow_thread_pool& pool, + std::size_t total_scheds, + std::size_t tid, + std::barrier<>& barrier, #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - std::span buffer, + std::span buffer, #endif - std::atomic& stop, - exec::numa_policy numa) { + std::atomic& stop, + exec::numa_policy numa) + { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); - auto scheduler = pool.get_scheduler(); - std::mutex mut; + auto scheduler = pool.get_scheduler(); + std::mutex mut; std::condition_variable cv; - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - pmr::monotonic_buffer_resource resource{ - buffer.data(), buffer.size(), pmr::null_memory_resource()}; + pmr::monotonic_buffer_resource resource{buffer.data(), + buffer.size(), + pmr::null_memory_resource()}; pmr::polymorphic_allocator alloc(&resource); auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - auto env = stdexec::prop{stdexec::get_allocator, alloc}; - while (scheds) { - exec::start_detached( - stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - }), - env); + auto env = stdexec::prop{stdexec::get_allocator, alloc}; + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + }), + env); --scheds; } #else auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - while (scheds) { - exec::start_detached(stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - })); + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + })); --scheds; } #endif @@ -82,6 +95,7 @@ struct RunThread { } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ my_main(argc, argv); } diff --git a/examples/benchmark/tbb_thread_pool.cpp b/examples/benchmark/tbb_thread_pool.cpp index d9da9379c..1d3514ee5 100644 --- a/examples/benchmark/tbb_thread_pool.cpp +++ b/examples/benchmark/tbb_thread_pool.cpp @@ -18,7 +18,8 @@ #include #include -struct RunThread { +struct RunThread +{ void operator()(exec::tbb::tbb_thread_pool& pool, std::size_t total_scheds, std::size_t tid, @@ -31,46 +32,58 @@ struct RunThread { { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); - auto scheduler = pool.get_scheduler(); - std::mutex mut; + auto scheduler = pool.get_scheduler(); + std::mutex mut; std::condition_variable cv; - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } #ifndef STDEXEC_NO_MONOTONIC_BUFFER_RESOURCE - pmr::monotonic_buffer_resource resource{ - buffer.data(), buffer.size(), pmr::null_memory_resource()}; + pmr::monotonic_buffer_resource resource{buffer.data(), + buffer.size(), + pmr::null_memory_resource()}; pmr::polymorphic_allocator alloc(&resource); auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - auto env = stdexec::prop{stdexec::get_allocator, alloc}; - while (scheds) { - exec::start_detached( - stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - }), - env); + auto env = stdexec::prop{stdexec::get_allocator, alloc}; + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + }), + env); --scheds; } #else auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; std::atomic counter{scheds}; - while (scheds) { - exec::start_detached(stdexec::schedule(scheduler) | stdexec::then([&] { - auto prev = counter.fetch_sub(1); - if (prev == 1) { - std::lock_guard lock{mut}; - cv.notify_one(); - } - })); + while (scheds) + { + exec::start_detached(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + auto prev = counter.fetch_sub(1); + if (prev == 1) + { + std::lock_guard lock{mut}; + cv.notify_one(); + } + })); --scheds; } #endif @@ -82,6 +95,7 @@ struct RunThread { } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ my_main(argc, argv); } diff --git a/examples/benchmark/tbb_thread_pool_nested.cpp b/examples/benchmark/tbb_thread_pool_nested.cpp index a5257560b..b8e448668 100644 --- a/examples/benchmark/tbb_thread_pool_nested.cpp +++ b/examples/benchmark/tbb_thread_pool_nested.cpp @@ -19,7 +19,8 @@ #include #include -struct RunThread { +struct RunThread +{ void operator()(exec::tbb::tbb_thread_pool& pool, std::size_t total_scheds, std::size_t tid, @@ -28,31 +29,41 @@ struct RunThread { [[maybe_unused]] std::span buffer, #endif std::atomic& stop, - exec::numa_policy numa) { + exec::numa_policy numa) + { int numa_node = numa.thread_index_to_node(tid); numa.bind_to_node(numa_node); auto scheduler = pool.get_scheduler(); - while (true) { + while (true) + { barrier.arrive_and_wait(); - if (stop.load()) { + if (stop.load()) + { break; } auto [start, end] = exec::_pool_::even_share(total_scheds, tid, pool.available_parallelism()); - std::size_t scheds = end - start; + std::size_t scheds = end - start; tbb::task_group tg{}; - stdexec::sync_wait(stdexec::schedule(scheduler) | stdexec::then([&] { - for (std::size_t i = 0; i < scheds; ++i) { - tg.run([&] { - // empty - }); - } - })); + stdexec::sync_wait(stdexec::schedule(scheduler) + | stdexec::then( + [&] + { + for (std::size_t i = 0; i < scheds; ++i) + { + tg.run( + [&] + { + // empty + }); + } + })); tg.wait(); barrier.arrive_and_wait(); } } }; -auto main(int argc, char** argv) -> int { +auto main(int argc, char** argv) -> int +{ my_main(argc, argv); } diff --git a/examples/hello_coro.cpp b/examples/hello_coro.cpp index 2b0459850..2ece71037 100644 --- a/examples/hello_coro.cpp +++ b/examples/hello_coro.cpp @@ -24,36 +24,42 @@ using namespace stdexec; template -auto async_answer(S1 s1, S2 s2) -> exec::task { +auto async_answer(S1 s1, S2 s2) -> exec::task +{ // Senders are implicitly awaitable (in this coroutine type): co_await static_cast(s2); co_return co_await static_cast(s1); } template -auto async_answer2(S1 s1, S2 s2) -> exec::task> { +auto async_answer2(S1 s1, S2 s2) -> exec::task> +{ co_return co_await stopped_as_optional(async_answer(s1, s2)); } // tasks have an associated stop token -auto async_stop_token() -> exec::task> { +auto async_stop_token() -> exec::task> +{ co_return co_await stopped_as_optional(get_stop_token()); } -auto main() -> int { - STDEXEC_TRY { +auto main() -> int +{ + STDEXEC_TRY + { // Awaitables are implicitly senders: auto [i] = stdexec::sync_wait(async_answer2(just(42), just())).value(); std::cout << "The answer is " << i.value() << '\n'; } - STDEXEC_CATCH(std::exception & e) { + STDEXEC_CATCH(std::exception & e) + { std::cerr << "error: " << e.what() << '\n'; } - STDEXEC_CATCH_ALL { + STDEXEC_CATCH_ALL + { std::cerr << "unknown error\n"; } } #else -int main() { -} +int main() {} #endif diff --git a/examples/hello_world.cpp b/examples/hello_world.cpp index 16902916c..665e83fee 100644 --- a/examples/hello_world.cpp +++ b/examples/hello_world.cpp @@ -23,12 +23,13 @@ using namespace stdexec; using stdexec::sync_wait; -auto main() -> int { - exec::numa_policy numa{exec::no_numa_policy{}}; +auto main() -> int +{ + exec::numa_policy numa{exec::no_numa_policy{}}; exec::static_thread_pool ctx{8}; - scheduler auto sch = ctx.get_scheduler(); // 1 + scheduler auto sch = ctx.get_scheduler(); // 1 - sender auto begin = schedule(sch); // 2 + sender auto begin = schedule(sch); // 2 sender auto hi_again = then( // 3 begin, // 3 [] { // 3 @@ -36,20 +37,25 @@ auto main() -> int { return 13; // 3 }); // 3 - sender auto add_42 = then(hi_again, [](int arg) { return arg + 42; }); // 4 - auto [i] = sync_wait(std::move(add_42)).value(); // 5 + sender auto add_42 = then(hi_again, [](int arg) { return arg + 42; }); // 4 + auto [i] = sync_wait(std::move(add_42)).value(); // 5 std::cout << "Result: " << i << std::endl; // Sync_wait provides a run_loop scheduler std::tuple t = sync_wait(get_scheduler()).value(); (void) t; - auto y = let_value(get_scheduler(), [](auto sched) { - return starts_on(sched, then(just(), [] { - std::cout << "from run_loop\n"; - return 42; - })); - }); + auto y = let_value(get_scheduler(), + [](auto sched) + { + return starts_on(sched, + then(just(), + [] + { + std::cout << "from run_loop\n"; + return 42; + })); + }); sync_wait(std::move(y)); sync_wait(when_all(just(42), get_scheduler(), get_stop_token())); diff --git a/examples/io_uring.cpp b/examples/io_uring.cpp index 33c80216c..971a4d424 100644 --- a/examples/io_uring.cpp +++ b/examples/io_uring.cpp @@ -27,44 +27,40 @@ #include -auto main() -> int { +auto main() -> int +{ exec::io_uring_context context; exec::io_uring_context context2; - std::thread io_thread{[&] { context.run_until_stopped(); }}; - std::thread io_thread2{[&] { context2.run_until_stopped(); }}; - auto scheduler = context.get_scheduler(); - auto scheduler2 = context2.get_scheduler(); + std::thread io_thread{[&] { context.run_until_stopped(); }}; + std::thread io_thread2{[&] { context2.run_until_stopped(); }}; + auto scheduler = context.get_scheduler(); + auto scheduler2 = context2.get_scheduler(); using namespace std::chrono_literals; - stdexec::sync_wait( - exec::when_any( - exec::schedule_after(scheduler, 1s) | stdexec::then([] { std::cout << "Hello, 1!\n"; }), - exec::schedule_after(scheduler2, 2s) | stdexec::then([] { std::cout << "Hello, 2!\n"; }) - | stdexec::upon_stopped([] { std::cout << "Hello, 2, stopped.\n"; }))); - - stdexec::sync_wait( - exec::when_any( - exec::schedule_after(scheduler, 1s) | stdexec::then([] { std::cout << "Hello, 1!\n"; }) - | stdexec::upon_stopped([] { std::cout << "Hello, 1, stopped.\n"; }), - exec::schedule_after(scheduler2, 500ms) | stdexec::then([] { std::cout << "Hello, 2!\n"; }) - | stdexec::upon_stopped([] { std::cout << "Hello, 2, stopped.\n"; }))); - - stdexec::sync_wait( - stdexec::when_all( - stdexec::schedule(scheduler) | stdexec::then([] { std::cout << "Hello, 0!\n"; }), - exec::schedule_after(scheduler, 1s) | stdexec::then([] { std::cout << "Hello, 1!\n"; }), - exec::schedule_after(scheduler2, 2s) | stdexec::then([] { std::cout << "Hello, 2!\n"; }), - exec::schedule_after(scheduler, 3s) | stdexec::then([] { std::cout << "Stop it!\n"; }), - exec::finally(exec::schedule_after(scheduler2, 4s), stdexec::just() | stdexec::then([&] { - context.request_stop(); - })), - exec::finally(exec::schedule_after(scheduler, 4s), stdexec::just() | stdexec::then([&] { - context2.request_stop(); - })), - exec::schedule_after(scheduler, 10s) | stdexec::then([] { std::cout << "Hello, world!\n"; }) - | stdexec::upon_stopped([] { std::cout << "Hello, stopped.\n"; }), - exec::schedule_after(scheduler2, 10s) | stdexec::then([] { std::cout << "Hello, world!\n"; }) - | stdexec::upon_stopped([] { std::cout << "Hello, stopped.\n"; }))); + stdexec::sync_wait(exec::when_any( + exec::schedule_after(scheduler, 1s) | stdexec::then([] { std::cout << "Hello, 1!\n"; }), + exec::schedule_after(scheduler2, 2s) | stdexec::then([] { std::cout << "Hello, 2!\n"; }) + | stdexec::upon_stopped([] { std::cout << "Hello, 2, stopped.\n"; }))); + + stdexec::sync_wait(exec::when_any( + exec::schedule_after(scheduler, 1s) | stdexec::then([] { std::cout << "Hello, 1!\n"; }) + | stdexec::upon_stopped([] { std::cout << "Hello, 1, stopped.\n"; }), + exec::schedule_after(scheduler2, 500ms) | stdexec::then([] { std::cout << "Hello, 2!\n"; }) + | stdexec::upon_stopped([] { std::cout << "Hello, 2, stopped.\n"; }))); + + stdexec::sync_wait(stdexec::when_all( + stdexec::schedule(scheduler) | stdexec::then([] { std::cout << "Hello, 0!\n"; }), + exec::schedule_after(scheduler, 1s) | stdexec::then([] { std::cout << "Hello, 1!\n"; }), + exec::schedule_after(scheduler2, 2s) | stdexec::then([] { std::cout << "Hello, 2!\n"; }), + exec::schedule_after(scheduler, 3s) | stdexec::then([] { std::cout << "Stop it!\n"; }), + exec::finally(exec::schedule_after(scheduler2, 4s), + stdexec::just() | stdexec::then([&] { context.request_stop(); })), + exec::finally(exec::schedule_after(scheduler, 4s), + stdexec::just() | stdexec::then([&] { context2.request_stop(); })), + exec::schedule_after(scheduler, 10s) | stdexec::then([] { std::cout << "Hello, world!\n"; }) + | stdexec::upon_stopped([] { std::cout << "Hello, stopped.\n"; }), + exec::schedule_after(scheduler2, 10s) | stdexec::then([] { std::cout << "Hello, world!\n"; }) + | stdexec::upon_stopped([] { std::cout << "Hello, stopped.\n"; }))); io_thread.join(); io_thread2.join(); @@ -83,15 +79,14 @@ auto main() -> int { while (!context.is_running()) ; - stdexec::sync_wait( - exec::when_any( - exec::schedule_after(scheduler, 1s) | stdexec::then([] { std::cout << "Hello, 1!\n"; }), - exec::schedule_after(scheduler, 500ms) | stdexec::then([] { std::cout << "Hello, 2!\n"; }))); + stdexec::sync_wait(exec::when_any(exec::schedule_after(scheduler, 1s) + | stdexec::then([] { std::cout << "Hello, 1!\n"; }), + exec::schedule_after(scheduler, 500ms) + | stdexec::then([] { std::cout << "Hello, 2!\n"; }))); auto time_point = std::chrono::steady_clock::now() + 1s; - stdexec::sync_wait(exec::schedule_at(scheduler, time_point) | stdexec::then([] { - std::cout << "Hello, schedule_at!\n"; - })); + stdexec::sync_wait(exec::schedule_at(scheduler, time_point) + | stdexec::then([] { std::cout << "Hello, schedule_at!\n"; })); static_assert(exec::timed_scheduler); diff --git a/examples/nvexec/maxwell_distributed.cu b/examples/nvexec/maxwell_distributed.cu index 748b70f22..c3158f52f 100644 --- a/examples/nvexec/maxwell_distributed.cu +++ b/examples/nvexec/maxwell_distributed.cu @@ -306,31 +306,31 @@ namespace distributed }; template - __host__ inline __device__ auto + inline __host__ __device__ auto grid_initializer(float dt, AccessorT accessor) -> grid_initializer_t { return {dt, accessor}; } - __host__ inline __device__ auto + inline __host__ __device__ auto right_nid(std::size_t cell_id, std::size_t col, std::size_t N) -> std::size_t { return col == N - 1 ? cell_id - (N - 1) : cell_id + 1; } - __host__ inline __device__ auto + inline __host__ __device__ auto left_nid(std::size_t cell_id, std::size_t col, std::size_t N) -> std::size_t { return col == 0 ? cell_id + N - 1 : cell_id - 1; } - __host__ inline __device__ auto + inline __host__ __device__ auto bottom_nid(std::size_t cell_id, std::size_t, std::size_t N) -> std::size_t { return cell_id - N; } - __host__ inline __device__ auto + inline __host__ __device__ auto top_nid(std::size_t cell_id, std::size_t, std::size_t N) -> std::size_t { return cell_id + N; @@ -359,7 +359,7 @@ namespace distributed }; template - __host__ inline __device__ auto update_h(AccessorT accessor) -> h_field_calculator_t + inline __host__ __device__ auto update_h(AccessorT accessor) -> h_field_calculator_t { return {accessor}; } @@ -417,7 +417,7 @@ namespace distributed }; template - __host__ inline __device__ auto + inline __host__ __device__ auto update_e(float *time, float dt, AccessorT accessor) -> e_field_calculator_t { std::size_t source_position = accessor.n / 2 + (accessor.n * (accessor.n / 2)); diff --git a/examples/problem.cpp b/examples/problem.cpp index c0811aa77..633885806 100644 --- a/examples/problem.cpp +++ b/examples/problem.cpp @@ -22,42 +22,43 @@ namespace ex = stdexec; -struct receiver_t { +struct receiver_t +{ using receiver_concept = ex::receiver_t; - void set_value() && noexcept { - } + void set_value() && noexcept {} template - void set_value(As...) && noexcept { - } + void set_value(As...) && noexcept + {} template - void set_error(Error) && noexcept { - } + void set_error(Error) && noexcept + {} - void set_stopped() && noexcept { - } + void set_stopped() && noexcept {} }; template -void check_if_pool_domain() { +void check_if_pool_domain() +{ using pool_domain = exec::_pool_::_static_thread_pool::domain; static_assert(std::is_same_v); } template -void check_if_inline_domain() { +void check_if_inline_domain() +{ static_assert(std::is_same_v); } template -void check_if_starts_inline_and_completes_on_pool(Sender, Receiver) { +void check_if_starts_inline_and_completes_on_pool(Sender, Receiver) +{ using receiver_env_t = ex::env_of_t; check_if_pool_domain< - ex::__detail::__completing_domain_t - >(); + ex::__detail::__completing_domain_t>(); check_if_inline_domain>(); // auto op_state = ex::connect(std::move(sender), std::move(receiver)); @@ -72,51 +73,59 @@ void print(T) { #endif template > -struct expect_value_receiver_ex { - T dest_; +struct expect_value_receiver_ex +{ + T dest_; Env env_{}; using receiver_concept = stdexec::receiver_t; explicit expect_value_receiver_ex(T dest) - : dest_(dest) { - } + : dest_(dest) + {} expect_value_receiver_ex(Env env, T dest) : dest_(dest) - , env_(std::move(env)) { - } + , env_(std::move(env)) + {} - void set_value(T val) noexcept { + void set_value(T val) noexcept + { dest_ = val; } template - void set_value(Ts...) noexcept { + void set_value(Ts...) noexcept + { std::cerr << "set_value called with wrong value types on expect_value_receiver_ex\n"; } - void set_stopped() noexcept { + void set_stopped() noexcept + { std::cerr << "set_stopped called on expect_value_receiver_ex\n"; } - void set_error(std::exception_ptr) noexcept { + void set_error(std::exception_ptr) noexcept + { std::cerr << "set_error called on expect_value_receiver_ex\n"; } - auto get_env() const noexcept -> Env { + auto get_env() const noexcept -> Env + { return env_; } }; template -inline auto _with_scheduler(Sched sched = {}) { +inline auto _with_scheduler(Sched sched = {}) +{ return ex::write_env(ex::prop{ex::get_scheduler, std::move(sched)}); } -int main() { +int main() +{ exec::static_thread_pool pool(3); - auto sched = pool.get_scheduler(); + auto sched = pool.get_scheduler(); // check_if_starts_inline_and_completes_on_pool(ex::schedule(sched), receiver_t{}); // check_if_starts_inline_and_completes_on_pool(ex::continues_on(ex::just(), sched), receiver_t{}); diff --git a/examples/retry.cpp b/examples/retry.cpp index 552a3edac..dcbc2f265 100644 --- a/examples/retry.cpp +++ b/examples/retry.cpp @@ -22,23 +22,28 @@ /////////////////////////////////////////////////////////////////////////////// // Example code: -struct fail_some { +struct fail_some +{ using sender_concept = stdexec::sender_t; - using completion_signatures = stdexec::completion_signatures< - stdexec::set_value_t(int), - stdexec::set_error_t(std::exception_ptr) - >; + using completion_signatures = + stdexec::completion_signatures; template - struct op { + struct op + { R r_; - void start() & noexcept { + void start() & noexcept + { static int i = 0; - if (++i < 3) { + if (++i < 3) + { std::printf("fail!\n"); stdexec::set_error(std::move(r_), std::exception_ptr{}); - } else { + } + else + { std::printf("success!\n"); stdexec::set_value(std::move(r_), 42); } @@ -46,12 +51,14 @@ struct fail_some { }; template - auto connect(R r) const -> op { + auto connect(R r) const -> op + { return {std::move(r)}; } }; -auto main() -> int { +auto main() -> int +{ auto x = retry(fail_some{}); // prints: // fail! diff --git a/examples/scope.cpp b/examples/scope.cpp index 299f262d7..8a166960c 100644 --- a/examples/scope.cpp +++ b/examples/scope.cpp @@ -27,34 +27,35 @@ using namespace stdexec; using stdexec::sync_wait; -struct noop_receiver { +struct noop_receiver +{ using receiver_concept = receiver_t; template - void set_value(_As&&...) noexcept { - } + void set_value(_As&&...) noexcept + {} - void set_error(std::exception_ptr) noexcept { - } + void set_error(std::exception_ptr) noexcept {} - void set_stopped() noexcept { - } + void set_stopped() noexcept {} [[nodiscard]] - auto get_env() const & noexcept { + auto get_env() const & noexcept + { return stdexec::prop{get_stop_token, stdexec::never_stop_token{}}; } }; -auto main() -> int { +auto main() -> int +{ exec::static_thread_pool ctx{1}; - exec::async_scope scope; + exec::async_scope scope; - scheduler auto sch = ctx.get_scheduler(); // 1 + scheduler auto sch = ctx.get_scheduler(); // 1 - sender auto begin = schedule(sch); // 2 + sender auto begin = schedule(sch); // 2 - sender auto printVoid = then(begin, []() noexcept { printf("void\n"); }); // 3 + sender auto printVoid = then(begin, []() noexcept { printf("void\n"); }); // 3 sender auto printEmpty = then( starts_on(sch, scope.on_empty()), @@ -62,25 +63,23 @@ auto main() -> int { printf("scope is empty\n"); }); - printf( - "\n" - "spawn void\n" - "==========\n"); + printf("\n" + "spawn void\n" + "==========\n"); - scope.spawn(printVoid); // 5 + scope.spawn(printVoid); // 5 sync_wait(printEmpty); - printf( - "\n" - "spawn void and 42\n" - "=================\n"); + printf("\n" + "spawn void and 42\n" + "=================\n"); - sender auto fortyTwo = then(begin, []() noexcept { return 42; }); // 6 + sender auto fortyTwo = then(begin, []() noexcept { return 42; }); // 6 - scope.spawn(printVoid); // 7 + scope.spawn(printVoid); // 7 - sender auto fortyTwoFuture = scope.spawn_future(fortyTwo); // 8 + sender auto fortyTwoFuture = scope.spawn_future(fortyTwo); // 8 sender auto printFortyTwo = then( std::move(fortyTwoFuture), @@ -88,10 +87,8 @@ auto main() -> int { printf("%d\n", fortyTwo); }); - sender auto allDone = - then(when_all(printEmpty, std::move(printFortyTwo)), [](auto&&...) noexcept { - printf("\nall done\n"); - }); // 10 + sender auto allDone = then(when_all(printEmpty, std::move(printFortyTwo)), + [](auto&&...) noexcept { printf("\nall done\n"); }); // 10 sync_wait(std::move(allDone)); @@ -103,7 +100,7 @@ auto main() -> int { { sender auto nest = scope.nest(begin); - auto op = connect(std::move(nest), noop_receiver{}); + auto op = connect(std::move(nest), noop_receiver{}); (void) op; } sync_wait(scope.on_empty()); diff --git a/examples/server_theme/let_value.cpp b/examples/server_theme/let_value.cpp index 3a53846bf..987c601fd 100644 --- a/examples/server_theme/let_value.cpp +++ b/examples/server_theme/let_value.cpp @@ -55,24 +55,27 @@ #if !STDEXEC_NO_STD_EXCEPTIONS() namespace ex = stdexec; -struct http_request { - std::string url_; +struct http_request +{ + std::string url_; std::vector> headers_; - std::string body_; + std::string body_; }; -struct http_response { - int status_code_; +struct http_response +{ + int status_code_; std::string body_; }; // Returns a sender that yields an http_request object for an incoming request template -auto schedule_request_start(S sched, int idx) -> ex::sender auto { +auto schedule_request_start(S sched, int idx) -> ex::sender auto +{ // app-specific-details: building of the http_request object auto url = std::string("/query?image_idx=") + std::to_string(idx); if (idx == 7) - url.clear(); // fake invalid request + url.clear(); // fake invalid request http_request req{.url_ = std::move(url), .headers_ = {}, .body_ = {}}; std::cout << "HTTP request " << idx << " arrived\n"; @@ -81,14 +84,16 @@ auto schedule_request_start(S sched, int idx) -> ex::sender auto { } // Sends a response back to the client; yields a void signal on success -auto send_response(const http_response& resp) -> ex::sender auto { +auto send_response(http_response const & resp) -> ex::sender auto +{ std::cout << "Sending back response: " << resp.status_code_ << "\n"; // Signal that we are done successfully return ex::just(); } // Validate that the HTTP request is well-formed -auto validate_request(const http_request& req) -> ex::sender auto { +auto validate_request(http_request const & req) -> ex::sender auto +{ std::cout << "validating request " << req.url_ << "\n"; if (req.url_.empty()) throw std::invalid_argument("No URL"); @@ -96,37 +101,49 @@ auto validate_request(const http_request& req) -> ex::sender auto { } // Handle the request; main application logic -auto handle_request(const http_request& req) -> ex::sender auto { +auto handle_request(http_request const & req) -> ex::sender auto +{ std::cout << "handling request " << req.url_ << "\n"; //... return ex::just(http_response{.status_code_ = 200, .body_ = "image details"}); } // Transforms server errors into responses to be sent to the client -auto error_to_response(std::exception_ptr err) -> ex::sender auto { - try { +auto error_to_response(std::exception_ptr err) -> ex::sender auto +{ + try + { std::rethrow_exception(err); - } catch (const std::invalid_argument& e) { + } + catch (std::invalid_argument const & e) + { return ex::just(http_response{.status_code_ = 404, .body_ = e.what()}); - } catch (const std::exception& e) { + } + catch (std::exception const & e) + { return ex::just(http_response{.status_code_ = 500, .body_ = e.what()}); - } catch (...) { + } + catch (...) + { return ex::just(http_response{.status_code_ = 500, .body_ = "Unknown server error"}); } } // Transforms cancellation of the server into responses to be sent to the client -auto stopped_to_response() -> ex::sender auto { +auto stopped_to_response() -> ex::sender auto +{ return ex::just(http_response{.status_code_ = 503, .body_ = "Service temporarily unavailable"}); } -auto main() -> int { +auto main() -> int +{ // Create a thread pool and get a scheduler from it exec::static_thread_pool pool{8}; - ex::scheduler auto sched = pool.get_scheduler(); + ex::scheduler auto sched = pool.get_scheduler(); // Fake a couple of requests - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 10; i++) + { // The whole flow for transforming incoming requests into responses ex::sender auto snd = // get a sender when a new request comes @@ -155,8 +172,9 @@ auto main() -> int { #else -int main() { +int main() +{ std::cout << "This example requires C++ exceptions to be enabled.\n"; return 0; } -#endif // !STDEXEC_NO_STD_EXCEPTIONS() +#endif // !STDEXEC_NO_STD_EXCEPTIONS() diff --git a/examples/server_theme/on_transfer.cpp b/examples/server_theme/on_transfer.cpp index 698bb5ad2..995c23a54 100644 --- a/examples/server_theme/on_transfer.cpp +++ b/examples/server_theme/on_transfer.cpp @@ -47,22 +47,25 @@ namespace ex = stdexec; -struct sync_stream { +struct sync_stream +{ private: static std::mutex s_mtx_; public: - std::ostream& sout_; + std::ostream& sout_; std::unique_lock lock_{s_mtx_}; template - friend auto operator<<(sync_stream&& self, const T& value) -> sync_stream&& { + friend auto operator<<(sync_stream&& self, T const & value) -> sync_stream&& + { self.sout_ << value; return std::move(self); } friend auto - operator<<(sync_stream&& self, std::ostream& (*manip)(std::ostream&) ) -> sync_stream&& { + operator<<(sync_stream&& self, std::ostream& (*manip)(std::ostream&) ) -> sync_stream&& + { self.sout_ << manip; return std::move(self); } @@ -70,35 +73,39 @@ struct sync_stream { std::mutex sync_stream::s_mtx_{}; -auto legacy_read_from_socket(int, char* buffer, size_t buffer_len) -> size_t { - const char fake_data[] = "Hello, world!"; - size_t sz = sizeof(fake_data) - 1; - size_t count = (std::min) (sz, buffer_len); +auto legacy_read_from_socket(int, char* buffer, size_t buffer_len) -> size_t +{ + char const fake_data[] = "Hello, world!"; + size_t sz = sizeof(fake_data) - 1; + size_t count = (std::min) (sz, buffer_len); std::memcpy(buffer, fake_data, count); return count; } -void process_read_data(const char* read_data, size_t read_len) { +void process_read_data(char const * read_data, size_t read_len) +{ sync_stream{.sout_ = std::cout} << "Processing '" << std::string_view{read_data, read_len} << "'\n"; } -auto main() -> int { +auto main() -> int +{ // Create a thread pool and get a scheduler from it exec::static_thread_pool work_pool{8}; - ex::scheduler auto work_sched = work_pool.get_scheduler(); + ex::scheduler auto work_sched = work_pool.get_scheduler(); exec::static_thread_pool io_pool{1}; - ex::scheduler auto io_sched = io_pool.get_scheduler(); + ex::scheduler auto io_sched = io_pool.get_scheduler(); std::array buffer; exec::async_scope scope; // Fake a couple of requests - for (int i = 0; i < 10; i++) { - int sock = i; - auto buf = reinterpret_cast(&buffer[0]); + for (int i = 0; i < 10; i++) + { + int sock = i; + auto buf = reinterpret_cast(&buffer[0]); // A sender that just calls the legacy read function auto snd_read = ex::just(sock, buf, buffer.size()) | ex::then(legacy_read_from_socket); diff --git a/examples/server_theme/split_bulk.cpp b/examples/server_theme/split_bulk.cpp index 71f1c5ce9..f363513f9 100644 --- a/examples/server_theme/split_bulk.cpp +++ b/examples/server_theme/split_bulk.cpp @@ -49,35 +49,44 @@ namespace ex = stdexec; -struct http_request { - std::string url_; +struct http_request +{ + std::string url_; std::vector> headers_; - std::string body_; + std::string body_; }; -struct http_response { - int status_code_; +struct http_response +{ + int status_code_; std::string body_; }; -struct image { +struct image +{ std::string image_data_; }; // Extract the image from the HTTP request -auto extract_image(http_request req) -> image { +auto extract_image(http_request req) -> image +{ return {req.body_}; } // Extract multiple images from the HTTP request -auto extract_images(http_request req) -> std::vector { +auto extract_images(http_request req) -> std::vector +{ std::vector res; - size_t last_idx = 0; - while (last_idx >= std::string::npos) { + size_t last_idx = 0; + while (last_idx >= std::string::npos) + { size_t idx = req.body_.find("\n", last_idx); - if (idx == std::string::npos) { + if (idx == std::string::npos) + { break; - } else { + } + else + { res.push_back(image{req.body_.substr(last_idx, idx - last_idx)}); last_idx = idx + 1; } @@ -88,41 +97,48 @@ auto extract_images(http_request req) -> std::vector { } // Convert the given set of images into the corresponding HTTP response -auto img3_to_response(const image& img1, const image& img2, const image& img3) -> http_response { +auto img3_to_response(image const & img1, image const & img2, image const & img3) -> http_response +{ std::ostringstream oss; oss << img1.image_data_ << ", " << img2.image_data_ << ", " << img3.image_data_ << "\n"; return {.status_code_ = 200, .body_ = oss.str()}; } // Convert the given set of images into the corresponding HTTP response -auto imgvec_to_response(const std::vector& imgs) -> http_response { +auto imgvec_to_response(std::vector const & imgs) -> http_response +{ std::ostringstream oss; - for (const auto& img: imgs) + for (auto const & img: imgs) oss << img.image_data_ << "\n"; return {.status_code_ = 200, .body_ = oss.str()}; } // Apply the Canny edge detector on the given image -auto apply_canny(const image& img) -> image { +auto apply_canny(image const & img) -> image +{ return {"canny / " + img.image_data_}; } // Apply the Sobel edge detector on the given image -auto apply_sobel(const image& img) -> image { +auto apply_sobel(image const & img) -> image +{ return {"sobel / " + img.image_data_}; } // Apply the Prewitt edge detector on the given image -auto apply_prewitt(const image& img) -> image { +auto apply_prewitt(image const & img) -> image +{ return {"prewitt / " + img.image_data_}; } // Apply blur filter on the given image -auto apply_blur(const image& img) -> image { +auto apply_blur(image const & img) -> image +{ return {"blur / " + img.image_data_}; } -auto handle_edge_detection_request(const http_request& req) -> ex::sender auto { +auto handle_edge_detection_request(http_request const & req) -> ex::sender auto +{ // extract the input image from the request ex::sender auto in_img_sender = ex::just(req) | ex::then(extract_image); @@ -132,31 +148,33 @@ auto handle_edge_detection_request(const http_request& req) -> ex::sender auto { // Apply the three methods of edge detection on the same input image, in parallel. // Then, join the results and generate the HTTP response - return ex::when_all( - multi_shot_img | ex::then(apply_canny), - multi_shot_img | ex::then(apply_sobel), - multi_shot_img | ex::then(apply_prewitt)) + return ex::when_all(multi_shot_img | ex::then(apply_canny), + multi_shot_img | ex::then(apply_sobel), + multi_shot_img | ex::then(apply_prewitt)) | // transform the resulting 3 images into an HTTP response ex::then(img3_to_response); // error and cancellation handling is performed outside } -auto handle_multi_blur_request(const http_request& req) -> ex::sender auto { +auto handle_multi_blur_request(http_request const & req) -> ex::sender auto +{ return // extract the input images from the request ex::just(req) | ex::then(extract_images) // process images in parallel with bulk. // use let_value to access the image count before calling bulk. - | ex::let_value([](std::vector imgs) { + | ex::let_value( + [](std::vector imgs) + { // get the image count size_t img_count = imgs.size(); // return a sender that bulk-processes the image in parallel return ex::just(std::move(imgs)) - | ex::bulk(ex::par, img_count, [](size_t i, std::vector& imgs) { - imgs[i] = apply_blur(imgs[i]); - }); + | ex::bulk(ex::par, + img_count, + [](size_t i, std::vector& imgs) { imgs[i] = apply_blur(imgs[i]); }); }) // transform the resulting 3 images into an HTTP response | ex::then(imgvec_to_response) @@ -164,14 +182,16 @@ auto handle_multi_blur_request(const http_request& req) -> ex::sender auto { ; } -auto main() -> int { +auto main() -> int +{ // Create a thread pool and get a scheduler from it exec::static_thread_pool pool{8}; - exec::async_scope scope; - ex::scheduler auto sched = pool.get_scheduler(); + exec::async_scope scope; + ex::scheduler auto sched = pool.get_scheduler(); // Fake a couple of edge_detect requests - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) + { // Create a test request http_request req{.url_ = "/edge_detect", .headers_ = {}, .body_ = "scene"}; @@ -179,17 +199,21 @@ auto main() -> int { ex::sender auto snd = handle_edge_detection_request(req); // Pack this into a simplified flow and execute it asynchronously - ex::sender auto action = std::move(snd) | ex::then([](http_response resp) { - std::ostringstream oss; - oss << "Sending response: " << resp.status_code_ << " / " - << resp.body_ << "\n"; - std::cout << oss.str(); - }); + ex::sender auto action = std::move(snd) + | ex::then( + [](http_response resp) + { + std::ostringstream oss; + oss << "Sending response: " << resp.status_code_ << " / " + << resp.body_ << "\n"; + std::cout << oss.str(); + }); scope.spawn(ex::starts_on(sched, std::move(action))); } // Fake a couple of multi_blur requests - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) + { // Create a test request http_request req{.url_ = "/multi_blur", .headers_ = {}, .body_ = "img1\nimg2\nimg3\nimg4\n"}; @@ -197,12 +221,15 @@ auto main() -> int { ex::sender auto snd = handle_multi_blur_request(req); // Pack this into a simplified flow and execute it asynchronously - ex::sender auto action = std::move(snd) | ex::then([](http_response resp) { - std::ostringstream oss; - oss << "Sending response: " << resp.status_code_ << " / " - << resp.body_ << "\n"; - std::cout << oss.str(); - }); + ex::sender auto action = std::move(snd) + | ex::then( + [](http_response resp) + { + std::ostringstream oss; + oss << "Sending response: " << resp.status_code_ << " / " + << resp.body_ << "\n"; + std::cout << oss.str(); + }); scope.spawn(ex::starts_on(sched, std::move(action))); } diff --git a/examples/server_theme/then_upon.cpp b/examples/server_theme/then_upon.cpp index 8ed76d279..3602ad60a 100644 --- a/examples/server_theme/then_upon.cpp +++ b/examples/server_theme/then_upon.cpp @@ -51,18 +51,21 @@ namespace ex = stdexec; -struct http_request { - std::string url_; +struct http_request +{ + std::string url_; std::vector> headers_; - std::string body_; + std::string body_; }; -struct http_response { - int status_code_; +struct http_response +{ + int status_code_; std::string body_; }; -enum class obj_type { +enum class obj_type +{ human, dog, cat, @@ -72,8 +75,10 @@ enum class obj_type { cancelled, }; -auto as_string(obj_type t) -> const char* { - switch (t) { +auto as_string(obj_type t) -> char const * +{ + switch (t) + { case obj_type::human: return "human"; case obj_type::dog: @@ -92,18 +97,21 @@ auto as_string(obj_type t) -> const char* { return "general error"; } -struct classification_result { - obj_type type_; - int accuracy_; +struct classification_result +{ + obj_type type_; + int accuracy_; std::string details_{}; }; -struct image { +struct image +{ std::string image_data_; }; // Extract the image from the HTTP request -auto extract_image(http_request req) -> image { +auto extract_image(http_request req) -> image +{ // TODO: make upon_error work before enabling this // if (req.body_.empty()) // throw std::invalid_argument("no image found"); @@ -111,7 +119,8 @@ auto extract_image(http_request req) -> image { } // Classify the image received -auto do_classify(image img) -> classification_result { +auto do_classify(image img) -> classification_result +{ if (img.image_data_ == "human") return {.type_ = obj_type::human, .accuracy_ = 93}; else if (img.image_data_ == "cat") @@ -124,24 +133,30 @@ auto do_classify(image img) -> classification_result { } // Check for errors and transform them into classification result -auto on_classification_error(std::exception_ptr) -> classification_result { +auto on_classification_error(std::exception_ptr) -> classification_result +{ return {.type_ = obj_type::general_error, .accuracy_ = 100, .details_ = {}}; } // Check for cancellation and transform it into classification result -auto on_classification_cancelled() -> classification_result { +auto on_classification_cancelled() -> classification_result +{ return {.type_ = obj_type::cancelled, .accuracy_ = 100}; } // Convert the classification result into an HTTP response -auto to_response(classification_result res) -> http_response { +auto to_response(classification_result res) -> http_response +{ if (res.type_ == obj_type::general_error) // Send a 500 response back if we have a general error return {.status_code_ = 500, .body_ = res.details_}; - else if (res.type_ == obj_type::cancelled) { + else if (res.type_ == obj_type::cancelled) + { // Send a 503 response back if the computation is cancelled return {.status_code_ = 503, .body_ = "cancelled"}; - } else { + } + else + { // Send a success response back, with the object type, accuracy and details std::ostringstream oss; oss << as_string(res.type_) << " (" << res.accuracy_ << ")\n" << res.details_; @@ -150,7 +165,8 @@ auto to_response(classification_result res) -> http_response { } // Handler for the "classify" request type -auto handle_classify_request(const http_request& req) -> ex::sender auto { +auto handle_classify_request(http_request const & req) -> ex::sender auto +{ return // start with the input buffer ex::just(req) @@ -169,16 +185,18 @@ auto handle_classify_request(const http_request& req) -> ex::sender auto { ; } -auto main() -> int { +auto main() -> int +{ // Create a thread pool and get a scheduler from it - exec::async_scope scope; + exec::async_scope scope; exec::static_thread_pool pool{8}; - ex::scheduler auto sched = pool.get_scheduler(); + ex::scheduler auto sched = pool.get_scheduler(); // Fake a couple of requests - for (int i = 0; i < 12; i++) { + for (int i = 0; i < 12; i++) + { // Create a test request - const char* body = ""; + char const * body = ""; if (i % 2 == 0) body = "human"; else if (i % 3 == 0) @@ -193,12 +211,15 @@ auto main() -> int { ex::sender auto snd = handle_classify_request(req); // Pack this into a simplified flow and execute it asynchronously - ex::sender auto action = std::move(snd) | ex::then([](http_response resp) { - std::ostringstream oss; - oss << "Sending response: " << resp.status_code_ << " / " - << resp.body_ << "\n"; - std::cout << oss.str(); - }); + ex::sender auto action = std::move(snd) + | ex::then( + [](http_response resp) + { + std::ostringstream oss; + oss << "Sending response: " << resp.status_code_ << " / " + << resp.body_ << "\n"; + std::cout << oss.str(); + }); scope.spawn(ex::starts_on(sched, std::move(action))); } diff --git a/examples/then.cpp b/examples/then.cpp index 5f2d3f661..4f3af5dcb 100644 --- a/examples/then.cpp +++ b/examples/then.cpp @@ -22,11 +22,14 @@ /////////////////////////////////////////////////////////////////////////////// // Example code: -auto main() -> int { - auto x = then(stdexec::just(42), [](int i) { - std::printf("Got: %d\n", i); - return i; - }); +auto main() -> int +{ + auto x = then(stdexec::just(42), + [](int i) + { + std::printf("Got: %d\n", i); + return i; + }); // prints: // Got: 42 diff --git a/include/._clangd_helper_file.cpp b/include/._clangd_helper_file.cpp index 6f579e4c3..c3c19b976 100644 --- a/include/._clangd_helper_file.cpp +++ b/include/._clangd_helper_file.cpp @@ -28,5 +28,4 @@ // than those in the parent (for example, if the subdirectory has a CMakeList.txt that defines additional executables). // This ensures clangd provides useful intellisense for headers in any subdirectory with a CMakeList.txt. -auto main() -> int { -} +auto main() -> int {} diff --git a/include/exec/detail/numa.hpp b/include/exec/detail/numa.hpp index 94b6ad7a6..a46047ceb 100644 --- a/include/exec/detail/numa.hpp +++ b/include/exec/detail/numa.hpp @@ -37,7 +37,7 @@ namespace experimental::execution { namespace _numa { - using _small_t = void* [1]; + using _small_t = void *[1]; template using _is_small = STDEXEC::__mbool; @@ -47,27 +47,27 @@ namespace experimental::execution _storage() noexcept = default; template Ty> - explicit _storage(Ty&& value) - : ptr{new STDEXEC::__decay_t{static_cast(value)}} + explicit _storage(Ty &&value) + : ptr{new STDEXEC::__decay_t{static_cast(value)}} {} template Ty> requires(_is_small>::value) - explicit _storage(Ty&& value) noexcept(STDEXEC::__nothrow_decay_copyable) + explicit _storage(Ty &&value) noexcept(STDEXEC::__nothrow_decay_copyable) : buf{} { - ::new (static_cast(buf)) STDEXEC::__decay_t{static_cast(value)}; + ::new (static_cast(buf)) STDEXEC::__decay_t{static_cast(value)}; } - void* ptr{}; + void *ptr{}; char buf[sizeof(_small_t)]; }; struct _vtable { - auto (*move)(_storage*, _storage*) noexcept -> void; - auto (*copy)(_storage*, _storage const *) -> void; - auto (*destroy)(_storage*) noexcept -> void; + auto (*move)(_storage *, _storage *) noexcept -> void; + auto (*copy)(_storage *, _storage const *) -> void; + auto (*destroy)(_storage *) noexcept -> void; auto (*num_nodes)(_storage const *) noexcept -> std::size_t; auto (*num_cpus)(_storage const *, int) noexcept -> std::size_t; auto (*bind_to_node)(_storage const *, int) noexcept -> int; @@ -78,7 +78,7 @@ namespace experimental::execution struct _vtable_for { // move - static auto _move(_storage* self, _storage* other) noexcept -> void + static auto _move(_storage *self, _storage *other) noexcept -> void { if constexpr (!_is_small::value) { @@ -86,13 +86,13 @@ namespace experimental::execution } else { - ::new (static_cast(self->buf)) - T{static_cast(*reinterpret_cast(other->buf))}; + ::new (static_cast(self->buf)) + T{static_cast(*reinterpret_cast(other->buf))}; } } // copy - static auto _copy(_storage* self, _storage const * other) noexcept -> void + static auto _copy(_storage *self, _storage const *other) noexcept -> void { if constexpr (!_is_small::value) { @@ -100,25 +100,25 @@ namespace experimental::execution } else { - ::new (static_cast(self->buf)) T{*reinterpret_cast(other->buf)}; + ::new (static_cast(self->buf)) T{*reinterpret_cast(other->buf)}; } } // destroy - static auto _destroy(_storage* self) noexcept -> void + static auto _destroy(_storage *self) noexcept -> void { if constexpr (!_is_small::value) { - delete static_cast(self->ptr); + delete static_cast(self->ptr); } else { - std::destroy_at(reinterpret_cast(self->buf)); + std::destroy_at(reinterpret_cast(self->buf)); } } // num_nodes - static auto _num_nodes(_storage const * self) noexcept -> std::size_t + static auto _num_nodes(_storage const *self) noexcept -> std::size_t { if constexpr (!_is_small::value) { @@ -131,7 +131,7 @@ namespace experimental::execution } // num_cpus - static auto _num_cpus(_storage const * self, int node) noexcept -> std::size_t + static auto _num_cpus(_storage const *self, int node) noexcept -> std::size_t { if constexpr (!_is_small::value) { @@ -144,7 +144,7 @@ namespace experimental::execution } // bind_to_node - static auto _bind_to_node(_storage const * self, int node) noexcept -> int + static auto _bind_to_node(_storage const *self, int node) noexcept -> int { if constexpr (!_is_small::value) { @@ -157,7 +157,7 @@ namespace experimental::execution } // thread_index_to_node - static auto _thread_index_to_node(_storage const * self, std::size_t index) noexcept -> int + static auto _thread_index_to_node(_storage const *self, std::size_t index) noexcept -> int { if constexpr (!_is_small::value) { @@ -184,24 +184,24 @@ namespace experimental::execution struct numa_policy { private: - _numa::_vtable const * vtable_; - _numa::_storage storage_; + _numa::_vtable const *vtable_; + _numa::_storage storage_; public: template NumaPolicy> - numa_policy(NumaPolicy&& policy) + numa_policy(NumaPolicy &&policy) : vtable_(&_numa::_vtable_for_v>) - , storage_(static_cast(policy)) + , storage_(static_cast(policy)) {} - numa_policy(numa_policy&& other) noexcept + numa_policy(numa_policy &&other) noexcept : vtable_(other.vtable_) , storage_{} { vtable_->move(&storage_, &other.storage_); } - numa_policy(numa_policy const & other) + numa_policy(numa_policy const &other) : vtable_(other.vtable_) , storage_{} { @@ -273,7 +273,7 @@ namespace experimental::execution { inline std::size_t _get_numa_num_cpus(int node) { - struct ::bitmask* cpus = ::numa_allocate_cpumask(); + struct ::bitmask *cpus = ::numa_allocate_cpumask(); if (!cpus) { return 0; @@ -290,7 +290,7 @@ namespace experimental::execution struct _node_to_thread_index { - static std::vector const & get() noexcept + static std::vector const &get() noexcept { // This leaks one memory block at shutdown, but it's fine. Clang's and gcc's leak // sanitizer do not report it. @@ -323,7 +323,7 @@ namespace experimental::execution int bind_to_node(int node) const noexcept { - struct ::bitmask* nodes = ::numa_allocate_nodemask(); + struct ::bitmask *nodes = ::numa_allocate_nodemask(); if (!nodes) { return -1; @@ -336,8 +336,8 @@ namespace experimental::execution int thread_index_to_node(std::size_t idx) const noexcept { - auto const & node_to_thread_index = _node_to_thread_index::get(); - int index = static_cast(idx) % node_to_thread_index.back(); + auto const &node_to_thread_index = _node_to_thread_index::get(); + int index = static_cast(idx) % node_to_thread_index.back(); auto it = std::upper_bound(node_to_thread_index.begin(), node_to_thread_index.end(), index); STDEXEC_ASSERT(it != node_to_thread_index.end()); return static_cast(std::distance(node_to_thread_index.begin(), it)); @@ -356,7 +356,7 @@ namespace experimental::execution template struct numa_allocator { - using pointer = T*; + using pointer = T *; using const_pointer = T const *; using value_type = T; @@ -365,28 +365,28 @@ namespace experimental::execution {} template - explicit numa_allocator(numa_allocator const & other) noexcept + explicit numa_allocator(numa_allocator const &other) noexcept : node_(other.node_) {} int node_; - void* do_allocate(std::size_t n) + void *do_allocate(std::size_t n) { return ::numa_alloc_onnode(n, node_); } - void do_deallocate(void* p, std::size_t n) + void do_deallocate(void *p, std::size_t n) { ::numa_free(p, n); } - T* allocate(std::size_t n) + T *allocate(std::size_t n) { - return static_cast(do_allocate(n * sizeof(T))); + return static_cast(do_allocate(n * sizeof(T))); } - void deallocate(T* p, std::size_t n) + void deallocate(T *p, std::size_t n) { do_deallocate(p, n * sizeof(T)); } @@ -410,7 +410,7 @@ namespace experimental::execution ::copy_bitmask_to_nodemask(::numa_no_nodes_ptr, &mask_); } - static nodemask const & any() noexcept + static nodemask const &any() noexcept { static STDEXEC::__indestructible const mask{make_any()}; return mask.get(); @@ -419,7 +419,7 @@ namespace experimental::execution bool operator[](std::size_t nodemask) const noexcept { ::bitmask mask; - mask.maskp = const_cast(mask_.n); + mask.maskp = const_cast(mask_.n); mask.size = sizeof(nodemask_t); return ::numa_bitmask_isbitset(&mask, static_cast(nodemask)); } @@ -427,7 +427,7 @@ namespace experimental::execution void set(std::size_t nodemask) noexcept { ::bitmask mask; - mask.maskp = const_cast(mask_.n); + mask.maskp = const_cast(mask_.n); mask.size = sizeof(nodemask_t); ::numa_bitmask_setbit(&mask, static_cast(nodemask)); } @@ -435,18 +435,18 @@ namespace experimental::execution bool get(std::size_t nodemask) const noexcept { ::bitmask mask; - mask.maskp = const_cast(mask_.n); + mask.maskp = const_cast(mask_.n); mask.size = sizeof(nodemask_t); return ::numa_bitmask_isbitset(&mask, static_cast(nodemask)); } - friend bool operator==(nodemask const & lhs, nodemask const & rhs) noexcept + friend bool operator==(nodemask const &lhs, nodemask const &rhs) noexcept { ::bitmask lhs_mask; ::bitmask rhs_mask; - lhs_mask.maskp = const_cast(lhs.mask_.n); + lhs_mask.maskp = const_cast(lhs.mask_.n); lhs_mask.size = sizeof(nodemask_t); - rhs_mask.maskp = const_cast(rhs.mask_.n); + rhs_mask.maskp = const_cast(rhs.mask_.n); rhs_mask.size = sizeof(nodemask_t); return ::numa_bitmask_equal(&lhs_mask, &rhs_mask); } @@ -471,7 +471,7 @@ namespace experimental::execution template struct numa_allocator { - using pointer = T*; + using pointer = T *; using const_pointer = T const *; using value_type = T; @@ -481,13 +481,13 @@ namespace experimental::execution explicit numa_allocator(numa_allocator const &) noexcept {} - auto allocate(std::size_t n) -> T* + auto allocate(std::size_t n) -> T * { std::allocator alloc{}; return alloc.allocate(n); } - void deallocate(T* p, std::size_t n) + void deallocate(T *p, std::size_t n) { std::allocator alloc{}; alloc.deallocate(p, n); @@ -525,7 +525,7 @@ namespace experimental::execution mask_ |= nodemask == 0; } - friend auto operator==(nodemask const & lhs, nodemask const & rhs) noexcept -> bool + friend auto operator==(nodemask const &lhs, nodemask const &rhs) noexcept -> bool { return lhs.mask_ == rhs.mask_; } diff --git a/include/exec/detail/system_context_replaceability_api.hpp b/include/exec/detail/system_context_replaceability_api.hpp index 5dbe1da0c..462f55bd9 100644 --- a/include/exec/detail/system_context_replaceability_api.hpp +++ b/include/exec/detail/system_context_replaceability_api.hpp @@ -60,9 +60,9 @@ namespace experimental::execution::system_context_replaceability /// Interface for completing a sender operation. Backend will call frontend though this interface /// for completing the `schedule` and `schedule_bulk` operations. - using receiver [[deprecated("Use STDEXEC::system_context_replaceability::receiver_proxy " - "instead.")]] = - STDEXEC::system_context_replaceability::receiver_proxy; + using receiver + [[deprecated("Use STDEXEC::system_context_replaceability::receiver_proxy " + "instead.")]] = STDEXEC::system_context_replaceability::receiver_proxy; /// Receiver for bulk scheduling operations. using bulk_item_receiver diff --git a/include/exec/sequence.hpp b/include/exec/sequence.hpp index 9f7097777..a7f2d3ef8 100644 --- a/include/exec/sequence.hpp +++ b/include/exec/sequence.hpp @@ -157,9 +157,9 @@ namespace experimental::execution STDEXEC_ATTRIBUTE(host, device) constexpr explicit _opstate(Rcvr&& rcvr, CvSndrs&& sndrs) : _opstate_base{static_cast(rcvr)} - , _sndrs{STDEXEC::__apply(__convert_tuple_fn<_senders_tuple_t>{}, - static_cast(sndrs))} - // move all but the first sender into the opstate. + , _sndrs{ + STDEXEC::__apply(__convert_tuple_fn<_senders_tuple_t>{}, static_cast(sndrs))} + // move all but the first sender into the opstate. { // Below, it looks like we are using `sndrs` after it has been moved from. This is not the // case. `sndrs` is moved into a tuple type that has `__ignore` for the first element. The diff --git a/include/exec/thread_pool_base.hpp b/include/exec/thread_pool_base.hpp index b4ebfe8a2..c19270fb1 100644 --- a/include/exec/thread_pool_base.hpp +++ b/include/exec/thread_pool_base.hpp @@ -341,9 +341,9 @@ namespace experimental::execution STDEXEC::__mbind_front_q, STDEXEC::__q>::value; - using bulk_rcvr = bulk_receiver; - using shared_state = bulk_shared_state; - using inner_opstate = STDEXEC::connect_result_t; + using bulk_rcvr = bulk_receiver; + using shared_state = bulk_shared_state; + using inner_opstate = STDEXEC::connect_result_t; void start() & noexcept { diff --git a/include/exec/timed_scheduler.hpp b/include/exec/timed_scheduler.hpp index 6e4b9dd31..7384c4412 100644 --- a/include/exec/timed_scheduler.hpp +++ b/include/exec/timed_scheduler.hpp @@ -150,13 +150,13 @@ namespace experimental::execution // __schedule_after_base_t class. template requires __callable<__schedule_after_base_t, _Scheduler, duration_of_t<_Scheduler> const &> - auto operator()(_Scheduler&& __sched, duration_of_t<_Scheduler> const & __time_point) const + auto operator()(_Scheduler &&__sched, duration_of_t<_Scheduler> const &__time_point) const noexcept(__nothrow_callable<__schedule_after_base_t, _Scheduler, duration_of_t<_Scheduler> const &>) -> __call_result_t<__schedule_after_base_t, _Scheduler, duration_of_t<_Scheduler> const &> { - return __schedule_after_base_t{}(static_cast<_Scheduler&&>(__sched), __time_point); + return __schedule_after_base_t{}(static_cast<_Scheduler &&>(__sched), __time_point); } #endif @@ -230,12 +230,12 @@ namespace experimental::execution // __schedule_at_base_t class. template requires __callable<__schedule_at_base_t, _Scheduler, time_point_of_t<_Scheduler> const &> - auto operator()(_Scheduler&& __sched, time_point_of_t<_Scheduler> const & __time_point) const + auto operator()(_Scheduler &&__sched, time_point_of_t<_Scheduler> const &__time_point) const noexcept( __nothrow_callable<__schedule_at_base_t, _Scheduler, time_point_of_t<_Scheduler> const &>) -> __call_result_t<__schedule_at_base_t, _Scheduler, time_point_of_t<_Scheduler> const &> { - return __schedule_at_base_t{}(static_cast<_Scheduler&&>(__sched), __time_point); + return __schedule_at_base_t{}(static_cast<_Scheduler &&>(__sched), __time_point); } #endif diff --git a/include/stdexec/__detail/__deprecations.hpp b/include/stdexec/__detail/__deprecations.hpp index 8775ca984..afbe0a8c4 100644 --- a/include/stdexec/__detail/__deprecations.hpp +++ b/include/stdexec/__detail/__deprecations.hpp @@ -40,9 +40,9 @@ namespace STDEXEC "inplace_stop_source")]] = inplace_stop_source; template - using in_place_stop_callback [[deprecated("in_place_stop_callback has been renamed " - "inplace_stop_callback")]] = - inplace_stop_callback<_Fun>; + using in_place_stop_callback + [[deprecated("in_place_stop_callback has been renamed " + "inplace_stop_callback")]] = inplace_stop_callback<_Fun>; using start_on_t [[deprecated("start_on_t has been renamed starts_on_t")]] = starts_on_t; [[deprecated("start_on has been renamed starts_on")]] diff --git a/include/stdexec/__detail/__domain.hpp b/include/stdexec/__detail/__domain.hpp index f97e64427..162d59db6 100644 --- a/include/stdexec/__detail/__domain.hpp +++ b/include/stdexec/__detail/__domain.hpp @@ -34,15 +34,15 @@ namespace STDEXEC { template concept __has_transform_sender = requires(_DomainOrTag __tag, - _Sender&& __sender, - _Env const &... __env) { + _Sender &&__sender, + _Env const &...__env) { __tag.transform_sender(_OpTag(), static_cast<_Sender &&>(__sender), __env...); }; template concept __has_nothrow_transform_sender = requires(_DomainOrTag __tag, - _Sender&& __sender, - _Env const &... __env) { + _Sender &&__sender, + _Env const &...__env) { { __tag.transform_sender(_OpTag(), static_cast<_Sender &&>(__sender), __env...) } noexcept; }; @@ -53,7 +53,7 @@ namespace STDEXEC __declval<_Env const &>()...)); template - concept __has_apply_sender = requires(_DomainOrTag __tag, _Args&&... __args) { + concept __has_apply_sender = requires(_DomainOrTag __tag, _Args &&...__args) { __tag.apply_sender(static_cast<_Args &&>(__args)...); }; @@ -67,28 +67,28 @@ namespace STDEXEC template requires __detail::__has_transform_sender, _OpTag, _Sender, _Env> STDEXEC_ATTRIBUTE(always_inline) - constexpr auto transform_sender(_OpTag, _Sender&& __sndr, _Env const & __env) const + constexpr auto transform_sender(_OpTag, _Sender &&__sndr, _Env const &__env) const noexcept(__detail::__has_nothrow_transform_sender, _OpTag, _Sender, _Env>) -> __detail::__transform_sender_result_t, _OpTag, _Sender, _Env> { - return tag_of_t<_Sender>().transform_sender(_OpTag(), static_cast<_Sender&&>(__sndr), __env); + return tag_of_t<_Sender>().transform_sender(_OpTag(), static_cast<_Sender &&>(__sndr), __env); } template STDEXEC_ATTRIBUTE(always_inline) - constexpr auto transform_sender(_OpTag, _Sender&& __sndr, _Env const &) const + constexpr auto transform_sender(_OpTag, _Sender &&__sndr, _Env const &) const noexcept(__nothrow_move_constructible<_Sender>) -> _Sender { - return static_cast<_Sender>(static_cast<_Sender&&>(__sndr)); + return static_cast<_Sender>(static_cast<_Sender &&>(__sndr)); } template requires __detail::__has_apply_sender<_Tag, _Args...> STDEXEC_ATTRIBUTE(always_inline) - constexpr auto apply_sender(_Tag, _Args&&... __args) const + constexpr auto apply_sender(_Tag, _Args &&...__args) const -> __detail::__apply_sender_result_t<_Tag, _Args...> { - return _Tag().apply_sender(static_cast<_Args&&>(__args)...); + return _Tag().apply_sender(static_cast<_Args &&>(__args)...); } }; @@ -129,13 +129,13 @@ namespace STDEXEC template requires __detail::__has_transform_sender, _OpTag, _Sndr, _Env> [[nodiscard]] - static constexpr auto transform_sender(_OpTag, _Sndr&& __sndr, _Env const & __env) + static constexpr auto transform_sender(_OpTag, _Sndr &&__sndr, _Env const &__env) noexcept(__detail::__has_nothrow_transform_sender, _OpTag, _Sndr, _Env>) -> __detail::__transform_sender_result_t, _OpTag, _Sndr, _Env> { static_assert((__default_domain_like<_Domains, _OpTag, _Sndr, _Env> && ...), "ERROR: indeterminate domains: cannot pick an algorithm customization"); - return tag_of_t<_Sndr>{}.transform_sender(_OpTag{}, static_cast<_Sndr&&>(__sndr), __env); + return tag_of_t<_Sndr>{}.transform_sender(_OpTag{}, static_cast<_Sndr &&>(__sndr), __env); } }; @@ -194,10 +194,9 @@ namespace STDEXEC using __scheduler_domain_t = __call_result_t, _Sch, _Env...>; - constexpr auto - __find_pos(bool const * const __begin, bool const * const __end) noexcept -> size_t + constexpr auto __find_pos(bool const *const __begin, bool const *const __end) noexcept -> size_t { - for (bool const * __where = __begin; __where != __end; ++__where) + for (bool const *__where = __begin; __where != __end; ++__where) { if (*__where) { @@ -212,17 +211,17 @@ namespace STDEXEC template struct __hide_query { - constexpr explicit __hide_query(_Env&& __env, _Queries...) noexcept - : __env_{static_cast<_Env&&>(__env)} + constexpr explicit __hide_query(_Env &&__env, _Queries...) noexcept + : __env_{static_cast<_Env &&>(__env)} {} template <__none_of<_Queries...> _Query, class... _As> requires __queryable_with<_Env, _Query, _As...> constexpr auto - operator()(_Query, _As&&... __as) const noexcept(__nothrow_queryable_with<_Env, _Query, _As...>) + operator()(_Query, _As &&...__as) const noexcept(__nothrow_queryable_with<_Env, _Query, _As...>) -> __query_result_t<_Env, _Query, _As...> { - return __query<_Query>()(__env_, static_cast<_As&&>(__as)...); + return __query<_Query>()(__env_, static_cast<_As &&>(__as)...); } private: @@ -231,20 +230,20 @@ namespace STDEXEC template STDEXEC_HOST_DEVICE_DEDUCTION_GUIDE - __hide_query(_Env&&, _Queries...) -> __hide_query<_Env, _Queries...>; + __hide_query(_Env &&, _Queries...) -> __hide_query<_Env, _Queries...>; //! @brief A wrapper around an environment that hides the get_scheduler and get_domain //! queries. template struct __hide_scheduler : __hide_query<_Env, get_scheduler_t, get_domain_t> { - constexpr explicit __hide_scheduler(_Env&& __env) noexcept - : __hide_query<_Env, get_scheduler_t, get_domain_t>{static_cast<_Env&&>(__env), {}, {}} + constexpr explicit __hide_scheduler(_Env &&__env) noexcept + : __hide_query<_Env, get_scheduler_t, get_domain_t>{static_cast<_Env &&>(__env), {}, {}} {} }; template - STDEXEC_HOST_DEVICE_DEDUCTION_GUIDE __hide_scheduler(_Env&&) -> __hide_scheduler<_Env>; + STDEXEC_HOST_DEVICE_DEDUCTION_GUIDE __hide_scheduler(_Env &&) -> __hide_scheduler<_Env>; ////////////////////////////////////////////////////////////////////////////////////////// //! @brief A query type for asking a sender's attributes for the domain on which that diff --git a/include/stdexec/__detail/__env.hpp b/include/stdexec/__detail/__env.hpp index c43130470..711bec425 100644 --- a/include/stdexec/__detail/__env.hpp +++ b/include/stdexec/__detail/__env.hpp @@ -42,7 +42,7 @@ namespace STDEXEC struct cprop { STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - static constexpr auto query(_Query, auto&&...) noexcept + static constexpr auto query(_Query, auto &&...) noexcept { return _Value; } @@ -56,11 +56,11 @@ namespace STDEXEC template <__forwarding_query _Query, class... _Args> requires __queryable_with<_Env, _Query, _Args...> STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto query(_Query, _Args&&... __args) const + constexpr auto query(_Query, _Args &&...__args) const noexcept(__nothrow_queryable_with<_Env, _Query, _Args...>) -> __query_result_t<_Env, _Query, _Args...> { - return __query<_Query>()(__env_, static_cast<_Args&&>(__args)...); + return __query<_Query>()(__env_, static_cast<_Args &&>(__args)...); } STDEXEC_ATTRIBUTE(no_unique_address) @@ -74,15 +74,15 @@ namespace STDEXEC { template STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto operator()(_Env&& __env) const -> decltype(auto) + constexpr auto operator()(_Env &&__env) const -> decltype(auto) { if constexpr (__decays_to<_Env, env<>> || __is_fwd_env<_Env>) { - return static_cast<_Env>(static_cast<_Env&&>(__env)); + return static_cast<_Env>(static_cast<_Env &&>(__env)); } else { - return __fwd<_Env>{static_cast<_Env&&>(__env)}; + return __fwd<_Env>{static_cast<_Env &&>(__env)}; } } }; @@ -94,20 +94,20 @@ namespace STDEXEC { template STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto operator()(_Env1&& __env1, _Env2&& __env2) const noexcept -> decltype(auto) + constexpr auto operator()(_Env1 &&__env1, _Env2 &&__env2) const noexcept -> decltype(auto) { if constexpr (__decays_to<_Env1, env<>>) { - return __fwd_fn()(static_cast<_Env2&&>(__env2)); + return __fwd_fn()(static_cast<_Env2 &&>(__env2)); } else if constexpr (__decays_to<_Env2, env<>>) { - return static_cast<_Env1>(static_cast<_Env1&&>(__env1)); + return static_cast<_Env1>(static_cast<_Env1 &&>(__env1)); } else { - return env<_Env1, __fwd_env_t<_Env2>>{{static_cast<_Env1&&>(__env1)}, - __fwd_fn()(static_cast<_Env2&&>(__env2))}; + return env<_Env1, __fwd_env_t<_Env2>>{{static_cast<_Env1 &&>(__env1)}, + __fwd_fn()(static_cast<_Env2 &&>(__env2))}; } } }; @@ -142,7 +142,7 @@ namespace STDEXEC constexpr auto operator()(_Env __env) const noexcept -> __join_env_t<__root_env, std::unwrap_reference_t<_Env>> { - return __join(__root_env{}, static_cast&&>(__env)); + return __join(__root_env{}, static_cast &&>(__env)); } }; @@ -160,7 +160,7 @@ namespace STDEXEC using __as_root_env_t = __result_of<__as_root_env, _Env>; template - concept __is_root_env = requires(_Env&& __env) { + concept __is_root_env = requires(_Env &&__env) { { __root_t{}(__env) } -> __std::same_as; }; @@ -170,7 +170,7 @@ namespace STDEXEC struct prop { STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto query(_Query, auto&&...) const noexcept -> _Value const & + constexpr auto query(_Query, auto &&...) const noexcept -> _Value const & { return __value; } @@ -217,22 +217,22 @@ namespace STDEXEC template requires __queryable_with<_Env1, _Query, _Args...> STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto query(_Query, _Args&&... __args) const + constexpr auto query(_Query, _Args &&...__args) const noexcept(__nothrow_queryable_with<_Env1, _Query, _Args...>) -> __query_result_t<_Env1, _Query, _Args...> { - return __query<_Query>()(__env1_, static_cast<_Args&&>(__args)...); + return __query<_Query>()(__env1_, static_cast<_Args &&>(__args)...); } template requires __queryable_with<_Env1, _Query, _Args...> || __queryable_with<_Env2, _Query, _Args...> STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto query(_Query, _Args&&... __args) const + constexpr auto query(_Query, _Args &&...__args) const noexcept(__nothrow_queryable_with<_Env2, _Query, _Args...>) -> __query_result_t<_Env2, _Query, _Args...> { - return __query<_Query>()(__env2_, static_cast<_Args&&>(__args)...); + return __query<_Query>()(__env2_, static_cast<_Args &&>(__args)...); } STDEXEC_ATTRIBUTE(no_unique_address) _Env1 __env1_; @@ -262,7 +262,7 @@ namespace STDEXEC template requires __detail::__has_get_env_member<_EnvProvider const &> STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto operator()(_EnvProvider const & __env_provider) const noexcept + constexpr auto operator()(_EnvProvider const &__env_provider) const noexcept -> __detail::__get_env_member_result_t<_EnvProvider const &> { static_assert(noexcept(__env_provider.get_env()), "get_env() members must be noexcept"); @@ -274,7 +274,7 @@ namespace STDEXEC || __tag_invocable [[deprecated("the use of tag_invoke for get_env is deprecated")]] STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) // - constexpr auto operator()(_EnvProvider const & __env_provider) const noexcept + constexpr auto operator()(_EnvProvider const &__env_provider) const noexcept -> __tag_invoke_result_t { static_assert(__nothrow_tag_invocable, diff --git a/include/stdexec/__detail/__get_completion_signatures.hpp b/include/stdexec/__detail/__get_completion_signatures.hpp index 5425a6516..4f4d9b8a5 100644 --- a/include/stdexec/__detail/__get_completion_signatures.hpp +++ b/include/stdexec/__detail/__get_completion_signatures.hpp @@ -69,14 +69,14 @@ namespace STDEXEC concept __non_sender = !enable_sender<__decay_t<_Ty>>; template <__valid_completion_signatures _Completions> - consteval auto __checked_complsigs(_Completions, void*) + consteval auto __checked_complsigs(_Completions, void *) { return _Completions(); } template requires(!__valid_completion_signatures<_Completions>) - consteval auto __checked_complsigs(_Completions, __mlist<_Sender, _Env...>*) + consteval auto __checked_complsigs(_Completions, __mlist<_Sender, _Env...> *) { if constexpr (__merror<_Completions>) { @@ -116,14 +116,14 @@ namespace STDEXEC using __legacy_member_alias_t = STDEXEC_REMOVE_REFERENCE(_Sender)::completion_signatures; template - concept __with_legacy_member = requires(__declfn_t<_Sender&&> __sndr, - __declfn_t<_Env&&>... __env) { + concept __with_legacy_member = requires(__declfn_t<_Sender &&> __sndr, + __declfn_t<_Env &&>... __env) { __sndr().get_completion_signatures(__env()...); }; template - concept __with_legacy_static_member = requires(__declfn_t<_Sender&&> __sndr, - __declfn_t<_Env&&>... __env) { + concept __with_legacy_static_member = requires(__declfn_t<_Sender &&> __sndr, + __declfn_t<_Env &&>... __env) { STDEXEC_REMOVE_REFERENCE(_Sender) ::static_get_completion_signatures(__sndr(), __env()...); }; @@ -166,8 +166,8 @@ namespace STDEXEC } // namespace __cmplsigs template - concept __has_get_completion_signatures = requires(__declfn_t<_Sender&&> __sndr, - __declfn_t<_Env&&> __env) { + concept __has_get_completion_signatures = requires(__declfn_t<_Sender &&> __sndr, + __declfn_t<_Env &&> __env) { { transform_sender(__sndr(), __env()) } -> __cmplsigs::__with<_Env>; }; @@ -260,13 +260,13 @@ namespace STDEXEC struct get_completion_signatures_t { template - constexpr auto operator()(_Sender&&) const noexcept + constexpr auto operator()(_Sender &&) const noexcept { return __cmplsigs::__get_completion_signatures_helper<_Sender>(); } template - constexpr auto operator()(_Sender&&, _Env const &) const noexcept + constexpr auto operator()(_Sender &&, _Env const &) const noexcept { using __new_sndr_t = transform_sender_result_t<_Sender, _Env>; static_assert(!__merror<__new_sndr_t>); @@ -295,7 +295,7 @@ namespace STDEXEC // Legacy interface: template requires(sizeof...(_Env) <= 1) - constexpr auto get_completion_signatures(_Sender&&, _Env const &...) noexcept + constexpr auto get_completion_signatures(_Sender &&, _Env const &...) noexcept { return STDEXEC::get_completion_signatures<_Sender, _Env...>(); } @@ -332,7 +332,7 @@ namespace STDEXEC (void) STDEXEC::get_completion_signatures<_Sender>(); return false; // didn't throw, not a dependent sender } - catch (dependent_sender_error&) + catch (dependent_sender_error &) { return true; } diff --git a/include/stdexec/__detail/__inline_scheduler.hpp b/include/stdexec/__detail/__inline_scheduler.hpp index fc7dcc5c8..ca70dbfed 100644 --- a/include/stdexec/__detail/__inline_scheduler.hpp +++ b/include/stdexec/__detail/__inline_scheduler.hpp @@ -45,7 +45,7 @@ namespace STDEXEC STDEXEC_ATTRIBUTE(host, device) constexpr void start() noexcept { - STDEXEC::set_value(static_cast<_Receiver&&>(__rcvr_)); + STDEXEC::set_value(static_cast<_Receiver &&>(__rcvr_)); } _Receiver __rcvr_; @@ -60,7 +60,7 @@ namespace STDEXEC STDEXEC_ATTRIBUTE(nodiscard, host, device) static constexpr auto connect(_Receiver __rcvr) noexcept -> __opstate<_Receiver> { - return {static_cast<_Receiver&&>(__rcvr)}; + return {static_cast<_Receiver &&>(__rcvr)}; } STDEXEC_ATTRIBUTE(nodiscard, host, device) diff --git a/include/stdexec/__detail/__memory.hpp b/include/stdexec/__detail/__memory.hpp index 9e93956ae..5ae8fb795 100644 --- a/include/stdexec/__detail/__memory.hpp +++ b/include/stdexec/__detail/__memory.hpp @@ -43,7 +43,7 @@ namespace STDEXEC template [[nodiscard]] - constexpr auto __allocate_unique(_Alloc const & __alloc, _Args&&... __args) + constexpr auto __allocate_unique(_Alloc const &__alloc, _Args &&...__args) -> std::unique_ptr<_Ty, __detail::__alloc_deleter<_Alloc>> { using __value_t = std::allocator_traits<_Alloc>::value_type; @@ -58,7 +58,7 @@ namespace STDEXEC 1ul}; std::allocator_traits<_Alloc>::construct(__alloc2, std::addressof(*__ptr), - static_cast<_Args&&>(__args)...); + static_cast<_Args &&>(__args)...); __guard.__dismiss(); return std::unique_ptr<_Ty, __deleter_t>(__ptr, __deleter_t{__alloc2}); } @@ -68,7 +68,7 @@ namespace STDEXEC // already bound to the correct type, in which case it is returned as-is. template [[nodiscard]] - constexpr auto __rebind_allocator(_Alloc const & __alloc) noexcept + constexpr auto __rebind_allocator(_Alloc const &__alloc) noexcept { using __rebound_alloc_t = std::allocator_traits<_Alloc>::template rebind_alloc<_Ty>; static_assert(noexcept(__rebound_alloc_t(__alloc))); @@ -78,7 +78,7 @@ namespace STDEXEC template requires __same_as<_Ty, typename _Alloc::value_type> [[nodiscard]] - constexpr auto __rebind_allocator(_Alloc const & __alloc) noexcept -> _Alloc const & + constexpr auto __rebind_allocator(_Alloc const &__alloc) noexcept -> _Alloc const & { return __alloc; // NOLINT(bugprone-return-const-ref-from-parameter) } diff --git a/include/stdexec/__detail/__queries.hpp b/include/stdexec/__detail/__queries.hpp index 9e0f5205c..62df2b7b7 100644 --- a/include/stdexec/__detail/__queries.hpp +++ b/include/stdexec/__detail/__queries.hpp @@ -119,14 +119,14 @@ namespace STDEXEC template <__forwarding_query _Query, class... _Args> requires __queryable_with, _Query, _Args...> [[nodiscard]] - constexpr auto query(_Query, _Args&&... __args) const + constexpr auto query(_Query, _Args &&...__args) const noexcept(__nothrow_queryable_with, _Query, _Args...>) -> __query_result_t, _Query, _Args...> { - return __query<_Query>()(get_env(__sndr_), static_cast<_Args&&>(__args)...); + return __query<_Query>()(get_env(__sndr_), static_cast<_Args &&>(__args)...); } - _Sender const & __sndr_; + _Sender const &__sndr_; }; template diff --git a/include/stdexec/__detail/__query.hpp b/include/stdexec/__detail/__query.hpp index e71c6393c..1c694773a 100644 --- a/include/stdexec/__detail/__query.hpp +++ b/include/stdexec/__detail/__query.hpp @@ -33,17 +33,17 @@ namespace STDEXEC template concept __member_queryable_with = __queryable<_Env> - && requires(_Env const & __env, - _Query const & __query, - __declfn_t<_Args&&>... __args) { + && requires(_Env const &__env, + _Query const &__query, + __declfn_t<_Args &&>... __args) { { __env.query(__query, __args()...) }; }; template concept __nothrow_member_queryable_with = __member_queryable_with<_Env, _Query, _Args...> - && requires(_Env const & __env, - _Query const & __query, - __declfn_t<_Args&&>... __args) { + && requires(_Env const &__env, + _Query const &__query, + __declfn_t<_Args &&>... __args) { { __env.query(__query, __args()...) } noexcept; }; @@ -65,7 +65,7 @@ namespace STDEXEC template STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto operator()(__ignore, _Args&&...) const noexcept // + constexpr auto operator()(__ignore, _Args &&...) const noexcept // -> __mcall1<_Transform, __mtypeof<_Default>> { return _Default; @@ -82,7 +82,7 @@ namespace STDEXEC template requires __member_queryable_with<_Env const &, _Qy, _Args...> STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) - constexpr auto operator()(_Env const & __env, _Args&&... __args) const + constexpr auto operator()(_Env const &__env, _Args &&...__args) const noexcept(__nothrow_member_queryable_with<_Env, _Qy, _Args...>) -> __mcall1<_Transform, __member_query_result_t<_Env, _Qy, _Args...>> { @@ -90,7 +90,7 @@ namespace STDEXEC { _Query::template __validate<_Env, _Args...>(); } - return __env.query(_Query(), static_cast<_Args&&>(__args)...); + return __env.query(_Query(), static_cast<_Args &&>(__args)...); } // Query with tag_invoke (legacy): @@ -98,7 +98,7 @@ namespace STDEXEC requires __tag_invocable<_Qy, _Env const &, _Args...> [[deprecated("the use of tag_invoke for queries is deprecated")]] STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) // - constexpr auto operator()(_Env const & __env, _Args&&... __args) const + constexpr auto operator()(_Env const &__env, _Args &&...__args) const noexcept(__nothrow_tag_invocable<_Qy, _Env const &, _Args...>) -> __mcall1<_Transform, __tag_invoke_result_t<_Qy, _Env const &, _Args...>> { @@ -106,21 +106,21 @@ namespace STDEXEC { _Query::template __validate<_Env, _Args...>(); } - return __tag_invoke(_Query(), __env, static_cast<_Args&&>(__args)...); + return __tag_invoke(_Query(), __env, static_cast<_Args &&>(__args)...); } }; template - concept __queryable_with = __callable<__query<_Query>, _Env&, _Args...>; + concept __queryable_with = __callable<__query<_Query>, _Env &, _Args...>; template - concept __nothrow_queryable_with = __nothrow_callable<__query<_Query>, _Env&, _Args...>; + concept __nothrow_queryable_with = __nothrow_callable<__query<_Query>, _Env &, _Args...>; template - using __query_result_t = __call_result_t<__query<_Query>, _Env&, _Args...>; + using __query_result_t = __call_result_t<__query<_Query>, _Env &, _Args...>; template - concept __statically_queryable_with_impl = requires(_Query __q, _Args&&... __args) { + concept __statically_queryable_with_impl = requires(_Query __q, _Args &&...__args) { std::remove_reference_t<_Env>::query(__q, static_cast<_Args &&>(__args)...); }; diff --git a/include/stdexec/__detail/__ranges.hpp b/include/stdexec/__detail/__ranges.hpp index caaf78d0a..2c21b6058 100644 --- a/include/stdexec/__detail/__ranges.hpp +++ b/include/stdexec/__detail/__ranges.hpp @@ -22,7 +22,8 @@ # include -namespace STDEXEC::ranges { +namespace STDEXEC::ranges +{ using std::ranges::begin; using std::ranges::end; @@ -30,7 +31,7 @@ namespace STDEXEC::ranges { using std::ranges::range_reference_t; using std::ranges::iterator_t; using std::ranges::sentinel_t; -} +} // namespace STDEXEC::ranges #else diff --git a/include/stdexec/__detail/__schedulers.hpp b/include/stdexec/__detail/__schedulers.hpp index bc76892b1..d27190a25 100644 --- a/include/stdexec/__detail/__schedulers.hpp +++ b/include/stdexec/__detail/__schedulers.hpp @@ -34,7 +34,7 @@ namespace STDEXEC ///////////////////////////////////////////////////////////////////////////// // [exec.schedule] template - concept __has_schedule_member = requires(_Scheduler&& __sched) { + concept __has_schedule_member = requires(_Scheduler &&__sched) { static_cast<_Scheduler &&>(__sched).schedule(); }; @@ -43,25 +43,25 @@ namespace STDEXEC template requires __has_schedule_member<_Scheduler> STDEXEC_ATTRIBUTE(host, device, always_inline) - auto operator()(_Scheduler&& __sched) const - noexcept(noexcept(static_cast<_Scheduler&&>(__sched).schedule())) - -> decltype(static_cast<_Scheduler&&>(__sched).schedule()) + auto operator()(_Scheduler &&__sched) const + noexcept(noexcept(static_cast<_Scheduler &&>(__sched).schedule())) + -> decltype(static_cast<_Scheduler &&>(__sched).schedule()) { - static_assert(sender(__sched).schedule())>, + static_assert(sender(__sched).schedule())>, "schedule() member functions must return a sender"); - return static_cast<_Scheduler&&>(__sched).schedule(); + return static_cast<_Scheduler &&>(__sched).schedule(); } template requires __has_schedule_member<_Scheduler> || __tag_invocable [[deprecated("the use of tag_invoke for schedule is deprecated")]] STDEXEC_ATTRIBUTE(host, device, always_inline) // - auto operator()(_Scheduler&& __sched) const + auto operator()(_Scheduler &&__sched) const noexcept(__nothrow_tag_invocable) -> __tag_invoke_result_t { static_assert(sender<__tag_invoke_result_t>); - return __tag_invoke(*this, static_cast<_Scheduler&&>(__sched)); + return __tag_invoke(*this, static_cast<_Scheduler &&>(__sched)); } static constexpr auto query(forwarding_query_t) noexcept -> bool @@ -84,7 +84,7 @@ namespace STDEXEC using schedule_result_t = __call_result_t; template - concept __scheduler_provider = requires(_SchedulerProvider const & __sp) { + concept __scheduler_provider = requires(_SchedulerProvider const &__sp) { { get_scheduler(__sp) } -> scheduler; }; @@ -154,7 +154,7 @@ namespace STDEXEC { template requires __queryable_with<_Attrs, _GetComplSch> - constexpr auto operator()(_Attrs const & __attrs, __ignore = {}) const noexcept + constexpr auto operator()(_Attrs const &__attrs, __ignore = {}) const noexcept -> __decay_t<__query_result_t<_Attrs, _GetComplSch>> { static_assert(noexcept(__attrs.query(_GetComplSch{}))); @@ -164,7 +164,7 @@ namespace STDEXEC template requires __queryable_with<_Attrs, _GetComplSch, _Env const &> - constexpr auto operator()(_Attrs const & __attrs, _Env const & __env) const noexcept + constexpr auto operator()(_Attrs const &__attrs, _Env const &__env) const noexcept -> __decay_t<__query_result_t<_Attrs, _GetComplSch, _Env const &>> { static_assert(noexcept(__attrs.query(_GetComplSch{}, __env))); @@ -181,7 +181,7 @@ namespace STDEXEC struct __recurse_query_t { template - constexpr auto operator()([[maybe_unused]] _Sch __sch, _Env const &... __env) const noexcept + constexpr auto operator()([[maybe_unused]] _Sch __sch, _Env const &...__env) const noexcept { static_assert(scheduler<_Sch>); // When determining where the scheduler's operations will complete, we query @@ -273,7 +273,7 @@ namespace STDEXEC template ()> - constexpr auto operator()(_Attrs const & __attrs, _Env const &... __env) const noexcept + constexpr auto operator()(_Attrs const &__attrs, _Env const &...__env) const noexcept -> __unless_one_of_t { // If __attrs has a completion scheduler, then return it (after checking the scheduler @@ -354,7 +354,7 @@ namespace STDEXEC template requires __sends<_Tag, _Sender, _Env...> using __completion_scheduler_of_t = - __call_result_t, env_of_t<_Sender>, const _Env&...>; + __call_result_t, env_of_t<_Sender>, const _Env &...>; // TODO(ericniebler): examine all uses of this struct. template @@ -363,7 +363,7 @@ namespace STDEXEC template STDEXEC_ATTRIBUTE(nodiscard, always_inline, host, device) constexpr auto query(get_completion_scheduler_t, - _Env const &... __env) const noexcept + _Env const &...__env) const noexcept -> __call_result_t, _Scheduler, _Env const &...> { return get_completion_scheduler(__sched_, __env...); @@ -411,7 +411,7 @@ namespace STDEXEC struct __mk_sch_env_t { template - constexpr auto operator()([[maybe_unused]] _Sch __sch, _Env const &... __env) const noexcept + constexpr auto operator()([[maybe_unused]] _Sch __sch, _Env const &...__env) const noexcept { if constexpr (__completes_inline>, _Env...> && (__callable || ...)) @@ -443,11 +443,11 @@ namespace STDEXEC && __infallible_sender<__result_of, _Env...>; // Deprecated interfaces - using get_delegatee_scheduler_t [[deprecated("get_delegatee_scheduler_t has been renamed " - "get_delegation_scheduler_t")]] = - get_delegation_scheduler_t; + using get_delegatee_scheduler_t + [[deprecated("get_delegatee_scheduler_t has been renamed " + "get_delegation_scheduler_t")]] = get_delegation_scheduler_t; - inline constexpr auto& get_delegatee_scheduler [[deprecated("get_delegatee_scheduler has been " + inline constexpr auto &get_delegatee_scheduler [[deprecated("get_delegatee_scheduler has been " "renamed get_delegation_scheduler")]] = get_delegation_scheduler; } // namespace STDEXEC diff --git a/include/stdexec/__detail/__transform_completion_signatures.hpp b/include/stdexec/__detail/__transform_completion_signatures.hpp index a6e6d0e19..480c94fe9 100644 --- a/include/stdexec/__detail/__transform_completion_signatures.hpp +++ b/include/stdexec/__detail/__transform_completion_signatures.hpp @@ -64,18 +64,18 @@ namespace STDEXEC template class _Tuple> using __for_each_sig_t = decltype(__cmplsigs::__for_each_sig<_Tuple>( - static_cast<_Sig*>(nullptr))); + static_cast<_Sig *>(nullptr))); template