examples

Toy examples in single C files.
git clone git://henryandlizzy.uk/examples
Log | Files | Refs

commit 1c262923cbf5f8b63c1b096145a8e85e25d24813
parent 8968680f2b50176103d4422573d64478cf5994d4
Author: Henry Wilson <henry@henryandlizzy.uk>
Date:   Fri, 22 Sep 2023 21:30:53 +0100

coro-poll: Use std::transform

Diffstat:
Msrc/coro-poll.cpp | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/coro-poll.cpp b/src/coro-poll.cpp @@ -4,9 +4,10 @@ #include <poll.h> #include <sys/timerfd.h> +#include <algorithm> +#include <cstdint> #include <iostream> #include <map> -#include <cstdint> static void check_err(char const* msg) { @@ -76,10 +77,11 @@ struct poll_scheduler if (not *this) return; - pollfd pfds[waiting.size()], *p = pfds; + pollfd pfds[waiting.size()]; - for (auto const& [fd, _] : waiting) - *p++ = {fd, POLLIN, 0}; + std::ranges::transform(waiting, pfds, [](auto const& x) { + return pollfd{x.first, POLLIN, 0}; + }); ::poll(pfds, waiting.size(), -1); check_err("poll");