error.hpp

1
2
3
4
5
6
7
#pragma once


#include <felspar/io/completion.hpp>


namespace felspar::io {

Wrapper around an IOP to directly expose errors instead of throwing

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    template<typename R>
    class [[nodiscard]] ec {
        iop<R> wrapped;

      public:
        ec(iop<R> &&i) : wrapped{std::move(i)} {}

        bool await_ready() const noexcept { return wrapped.await_ready(); }
        felspar::coro::coroutine_handle<>
                await_suspend(felspar::coro::coroutine_handle<> h) {
            return wrapped.await_suspend(h);
        }
        auto await_resume() { return std::move(wrapped.comp->result); }
    };


}