@@ -50,6 +50,23 @@ namespace winrt::impl
5050
5151 struct resume_apartment_context
5252 {
53+ resume_apartment_context () = default ;
54+ resume_apartment_context (std::nullptr_t ) : m_context(nullptr ), m_context_type(-1 ) {}
55+ resume_apartment_context (resume_apartment_context const &) = default ;
56+ resume_apartment_context (resume_apartment_context&& other) noexcept :
57+ m_context (std::move(other.m_context)), m_context_type(std::exchange(other.m_context_type, -1 )) {}
58+ resume_apartment_context& operator =(resume_apartment_context const &) = default ;
59+ resume_apartment_context& operator =(resume_apartment_context&& other) noexcept
60+ {
61+ m_context = std::move (other.m_context );
62+ m_context_type = std::exchange (other.m_context_type , -1 );
63+ return *this ;
64+ }
65+ bool valid () const noexcept
66+ {
67+ return m_context_type >= 0 ;
68+ }
69+
5370 com_ptr<IContextCallback> m_context = try_capture<IContextCallback>(WINRT_IMPL_CoGetObjectContext);
5471 int32_t m_context_type = get_apartment_type().first;
5572 };
@@ -88,6 +105,7 @@ namespace winrt::impl
88105
89106 inline auto resume_apartment (resume_apartment_context const & context, coroutine_handle<> handle)
90107 {
108+ WINRT_ASSERT (context.valid ());
91109 if ((context.m_context == nullptr ) || (context.m_context == try_capture<IContextCallback>(WINRT_IMPL_CoGetObjectContext)))
92110 {
93111 handle ();
@@ -338,6 +356,12 @@ WINRT_EXPORT namespace winrt
338356
339357 struct apartment_context
340358 {
359+ apartment_context () = default ;
360+ apartment_context (std::nullptr_t ) : context(nullptr ) { }
361+
362+ operator bool () const noexcept { return context.valid (); }
363+ bool operator !() const noexcept { return !context.valid (); }
364+
341365 bool await_ready () const noexcept
342366 {
343367 return false ;
0 commit comments