jbaldwin / libcoro

C++20 coroutine library
Apache License 2.0
599 stars 62 forks source link

Fix rvalue reference instantiation of coro::task #181

Closed a858438680 closed 1 year ago

a858438680 commented 1 year ago

This pull request fixes the problem that coro::task<int&&> cannot be constructed.

When return_type is reference_type, the promise::result() always returns return_type When return_type is not reference_type, the promise::result() either returns const return_type& by decltype(m_return_value.value()) or returns return_type&& by decltype(std::move(m_return_value.value())

The pull request also reduces the size of promise when return_type is reference type. The underlying held type for reference return type is changed from std::optional<std::reference_wrapper<std::remove_reference<return_type>>> to std::remove_reference<return_type>*. The typical size of std::optional<std::reference_wrapper<int>> is 16 and the size of pointer is typically 8.