-
Notifications
You must be signed in to change notification settings - Fork 264
Description
It might be useful in cases where a template uses a C++/WinRT projection type, to constrain that template to only types deriving from another projection type.
This can currently be achieved multiple ways:
template<typename T>
requires std::derived_from<T, winrt::impl::base_one<T, winrt::Windows::UI::Xaml::Controls::Page>>
class XamlPageHost final : public BaseXamlPageHost {template<typename T>
requires std::convertible_to<T, winrt::Windows::UI::Xaml::Controls::Page>
class XamlPageHost final : public BaseXamlPageHost {The problem with solution 1 is that it taps into implementation details of C++/WinRT, which is undesirable for a consumer of the library, but it is a reliable way currently to detect if T derives from Page.
Solution 2 has the issue that if some other non-projection type offers a conversion operator to the desired projection type, the template will match.
To resolve this situation, there should be a winrt::is_derived_from<T, U> type trait (and winrt::is_derived_from_v shorthand) which would have a static constexpr member value that is true, if the projection type T derives from type U.