diff --git a/src/test1.cpp b/src/test1.cpp index da76d50..67fcb13 100644 --- a/src/test1.cpp +++ b/src/test1.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include template @@ -11,8 +12,20 @@ struct coroutine: std::coroutine_handle>{ using promise_type = ::Promise; }; +struct RAII{ + std::string name; + RAII(const std::string &s):name(s){ + std::cout<<__FUNCTION__<<" "< struct Promise{ + Promise():raii("in promise"){}; + RAII raii; auto initial_suspend(){ std::cout<<__FUNCTION__<<'\n'; return std::suspend_always{}; @@ -37,11 +50,13 @@ struct Promise{ std::cout<<__FUNCTION__<<' '< h; }; + + coroutine test(){ + RAII raii("in test"); std::cout<<"testing\n"; co_yield 1; co_yield 2; @@ -56,4 +71,5 @@ int main(){ handle.resume(); std::cout<<__FUNCTION__<<'\n'; } + handle.destroy();//如果不destroy()那么~RAII in promise将不会显示,也不能将destroy()交给~Promise()管理,也不会~RAII in promise } \ No newline at end of file