From 8a9d4aa7b3b6411867249b4a55b0e5e8226d793b Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Thu, 17 Jul 2025 10:20:53 +0800 Subject: [PATCH] update --- src/test1.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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