template Generator::Generator(Generator &&tmp) noexcept : d_handle(tmp.d_handle) { tmp.d_handle = nullptr; } template Generator::~Generator() { if (d_handle) d_handle.destroy(); } template Generator &Generator::operator=(Generator &&tmp) noexcept { swap(tmp); return *this; } template Iterator Generator::begin() { if (d_handle) { d_handle.resume(); if (d_handle.done()) d_handle.promise().rethrow_if_exception(); } return Iterator{ d_handle }; } template inline Sentinel Generator::end() noexcept { return Sentinel{}; } template inline void Generator::swap(Generator &other) noexcept { std::swap(d_handle, other.d_handle); } template inline Generator::Generator(Handle handle) noexcept : d_handle(handle) {} //------------------------------------------------ template Generator< std::invoke_result_t< FUNC &, typename Generator::iterator::reference> > fmap(FUNC func, Generator source) { for (auto &&value: source) co_yield std::invoke( func, static_cast(value) ); }