1
0
mirror of https://github.com/tearshark/librf.git synced 2024-10-02 00:00:11 +08:00

语法更符合C++17标准

This commit is contained in:
tearshark 2018-03-27 00:43:36 +08:00
parent 803cc2e51e
commit eac8d3bd20
5 changed files with 14 additions and 5 deletions

View File

@ -38,12 +38,12 @@ namespace resumef
#endif
template<class callee_t, class = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, channel_read_awaker_ptr>::value>>
auto read(callee_t && awaker)
decltype(auto) read(callee_t && awaker)
{
return read_(std::make_shared<channel_read_awaker>(std::forward<callee_t>(awaker)));
}
template<class callee_t, class _Ty2, class = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, channel_write_awaker_ptr>::value>>
auto write(callee_t && awaker, _Ty2&& val)
decltype(auto) write(callee_t && awaker, _Ty2&& val)
{
return write_(std::make_shared<channel_write_awaker>(std::forward<callee_t>(awaker)), std::forward<_Ty2>(val));
}

View File

@ -29,7 +29,7 @@ namespace resumef
RF_API bool wait_(const event_awaker_ptr & awaker);
template<class callee_t, class dummy_t = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, event_awaker_ptr>::value>>
auto wait(callee_t && awaker, dummy_t * dummy_ = nullptr)
decltype(auto) wait(callee_t && awaker, dummy_t * dummy_ = nullptr)
{
return wait_(std::make_shared<event_awaker>(std::forward<callee_t>(awaker)));
}
@ -183,7 +183,6 @@ namespace resumef
return std::move(evts);
}
public:
inline future_t<bool> wait_for_(const clock_type::duration & dt) const
{
return wait_until_(clock_type::now() + dt);

View File

@ -72,6 +72,9 @@ namespace resumef
template <typename T = void>
struct future_t : public future_impl_t<T>
{
using state_type = typename future_impl_t<T>::state_type;
using future_impl_t<T>::_state;
future_t(const counted_ptr<state_type>& state)
: future_impl_t<T>(state)
{
@ -110,6 +113,8 @@ namespace resumef
template <>
struct future_t<void> : public future_impl_t<void>
{
using future_impl_t<void>::_state;
future_t(const counted_ptr<state_type>& state)
: future_impl_t<void>(state)
{
@ -246,6 +251,7 @@ namespace resumef
struct promise_t : public promise_impl_t<T>
{
typedef promise_t<T> promise_type;
using promise_impl_t<T>::_state;
//------------------------------------------------------------------------------------------
//以下是与编译器生成的resumable function交互的接口
@ -275,6 +281,7 @@ namespace resumef
struct promise_t<void> : public promise_impl_t<void>
{
typedef promise_t<void> promise_type;
using promise_impl_t<void>::_state;
//------------------------------------------------------------------------------------------
//以下是与编译器生成的resumable function交互的接口

View File

@ -28,7 +28,7 @@ namespace resumef
RF_API void unlock();
template<class callee_t, class dummy_t = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, mutex_awaker_ptr>::value>>
auto lock(callee_t && awaker, dummy_t * dummy_ = nullptr)
decltype(auto) lock(callee_t && awaker, dummy_t * dummy_ = nullptr)
{
return lock_(std::make_shared<mutex_awaker>(std::forward<callee_t>(awaker)));
}

View File

@ -149,6 +149,9 @@ namespace resumef
template<class _Ctx>
struct ctx_task_t : public task_t<typename std::result_of<_Ctx()>::type>
{
typedef task_t<typename std::result_of<_Ctx()>::type> base_type;
using base_type::_future;
typedef _Ctx context_type;
context_type _context;