зеркало из https://github.com/microsoft/cppwinrt.git
Add deduction guides for agile_ref and weak_ref (#955)
This commit is contained in:
Родитель
f204e39d29
Коммит
06ae44406d
|
@ -209,8 +209,10 @@ WINRT_EXPORT namespace winrt
|
|||
com_ptr<impl::IAgileReference> m_ref;
|
||||
};
|
||||
|
||||
template<typename T> agile_ref(T const&)->agile_ref<impl::wrapped_type_t<T>>;
|
||||
|
||||
template <typename T>
|
||||
agile_ref<T> make_agile(T const& object)
|
||||
agile_ref<impl::wrapped_type_t<T>> make_agile(T const& object)
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ WINRT_EXPORT namespace winrt
|
|||
com_ptr<impl::IWeakReference> m_ref;
|
||||
};
|
||||
|
||||
template<typename T> weak_ref(T const&)->weak_ref<impl::wrapped_type_t<T>>;
|
||||
|
||||
template<typename T>
|
||||
struct impl::abi<weak_ref<T>> : impl::abi<com_ptr<impl::IWeakReference>>
|
||||
{
|
||||
|
|
|
@ -98,6 +98,12 @@ TEST_CASE("weak,source")
|
|||
IStringable b = w.get();
|
||||
REQUIRE(b.ToString() == L"Weak");
|
||||
}
|
||||
|
||||
// Verify that deduction guides work.
|
||||
static_assert(std::is_same_v<weak_ref<IStringable>, decltype(weak_ref(IStringable()))>);
|
||||
static_assert(std::is_same_v<weak_ref<Uri>, decltype(weak_ref(std::declval<Uri>()))>);
|
||||
static_assert(std::is_same_v<weak_ref<::IPersist>, decltype(weak_ref(com_ptr<::IPersist>()))>);
|
||||
static_assert(std::is_same_v<weak_ref<::IPersist>, decltype(make_weak(com_ptr<::IPersist>()))>);
|
||||
}
|
||||
|
||||
TEST_CASE("weak,nullptr")
|
||||
|
|
|
@ -51,4 +51,10 @@ TEST_CASE("agile_ref")
|
|||
agile_ref<IStringable> empty;
|
||||
IStringable object = empty.get();
|
||||
REQUIRE(object == nullptr);
|
||||
|
||||
// Verify that deduction guides work.
|
||||
static_assert(std::is_same_v<agile_ref<IStringable>, decltype(agile_ref(object))>);
|
||||
static_assert(std::is_same_v<agile_ref<Uri>, decltype(agile_ref(std::declval<Uri>()))>);
|
||||
static_assert(std::is_same_v<agile_ref<::IPersist>, decltype(agile_ref(com_ptr<::IPersist>()))>);
|
||||
static_assert(std::is_same_v<agile_ref<::IPersist>, decltype(make_agile(com_ptr<::IPersist>()))>);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче