boostorg / cobalt

Coroutines for C++20 & asio
https://www.boost.org/doc/libs/master/libs/cobalt/doc/html/index.html
207 stars 24 forks source link

cobalt::channel does not work with move only type #183

Closed dchansen closed 4 months ago

dchansen commented 4 months ago

The channel class requires that the value type be copyable, so things like unique_ptrs cannot be used with it.

This example (for instance) does not compile:


#include <boost/cobalt.hpp>
#include <any>
#include <memory>

namespace bc = boost::cobalt;

struct OnlyOne {
    OnlyOne() = default;
    OnlyOne(const OnlyOne&) = delete;
    OnlyOne( OnlyOne&&) = default;
};

bc::task<void> test(){
    bc::channel<OnlyOne> c;
    co_await c.write(OnlyOne());       
}

See godbolt

klemens-morgenstern commented 4 months ago

Thanks for reporting. I created fixes for both your issues, can you check if they fix all problems?

dchansen commented 4 months ago

Thanks for the quick response. Your patch fixed both issues.