Skip to content

Commit 36759dc

Browse files
authored
Support boxing delegates (#810)
1 parent 5b96f54 commit 36759dc

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

strings/base_reference_produce.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ namespace winrt::impl
266266
template <typename T, typename From>
267267
T unbox_value_type(From&& value)
268268
{
269-
static_assert(!is_com_interface_v<T>);
270-
271269
if (!value)
272270
{
273271
throw hresult_no_interface();

test/test/box_delegate.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "pch.h"
2+
3+
TEST_CASE("box_delegate")
4+
{
5+
using Handler = winrt::Windows::Foundation::TypedEventHandler<int, bool>;
6+
7+
Handler d = [](auto&&...) {};
8+
REQUIRE(d);
9+
10+
auto box = winrt::box_value(d);
11+
12+
Handler unbox = winrt::unbox_value<Handler>(box);
13+
REQUIRE(winrt::get_abi(unbox) == winrt::get_abi(d));
14+
15+
unbox = winrt::unbox_value_or<Handler>(box, Handler {});
16+
REQUIRE(winrt::get_abi(unbox) == winrt::get_abi(d));
17+
18+
unbox = winrt::unbox_value_or<Handler>(winrt::Windows::Foundation::IInspectable{}, Handler{});
19+
REQUIRE(!unbox);
20+
}

test/test/test.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
<ClCompile Include="async_completed.cpp" />
297297
<ClCompile Include="async_propagate_cancel.cpp" />
298298
<ClCompile Include="async_ref_result.cpp" />
299+
<ClCompile Include="box_delegate.cpp" />
299300
<ClCompile Include="box_guid.cpp" />
300301
<ClCompile Include="capture.cpp" />
301302
<ClCompile Include="coro_foundation.cpp">

0 commit comments

Comments
 (0)