@@ -253,24 +253,24 @@ namespace winrt::impl
253253 template <>
254254 struct interface_list <>
255255 {
256- template <typename T, typename Predicate >
257- static constexpr void * find (const T*, const Predicate& ) noexcept
256+ template <typename Traits >
257+ static constexpr auto find (Traits const & traits ) noexcept
258258 {
259- return nullptr ;
259+ return traits. not_found () ;
260260 }
261261 };
262262
263263 template <typename First, typename ... Rest>
264264 struct interface_list <First, Rest...>
265265 {
266- template <typename T, typename Predicate >
267- static constexpr void * find (const T* obj, const Predicate& pred ) noexcept
266+ template <typename Traits >
267+ static constexpr auto find (Traits const & traits ) noexcept
268268 {
269- if (pred .template test <First>())
269+ if (traits .template test <First>())
270270 {
271- return to_abi <First>(obj );
271+ return traits. template found <First>();
272272 }
273- return interface_list<Rest...>::find (obj, pred );
273+ return interface_list<Rest...>::find (traits );
274274 }
275275 using first_interface = First;
276276 };
@@ -362,34 +362,88 @@ namespace winrt::impl
362362 using type = typename implements_default_interface<T>::type;
363363 };
364364
365- struct iid_finder
365+ template <typename T>
366+ struct find_iid_traits
366367 {
367- const guid& m_guid;
368+ T const * m_object;
369+ guid const & m_guid;
368370
369371 template <typename I>
370372 constexpr bool test () const noexcept
371373 {
372374 return is_guid_of<typename default_interface<I>::type>(m_guid);
373375 }
376+
377+ template <typename I>
378+ constexpr void * found () const noexcept
379+ {
380+ return to_abi<I>(m_object);
381+ }
382+
383+ static constexpr void * not_found () noexcept
384+ {
385+ return nullptr ;
386+ }
374387 };
375388
376389 template <typename T>
377- auto find_iid (const T * obj, const guid& iid) noexcept
390+ auto find_iid (T const * obj, guid const & iid) noexcept
378391 {
379- return static_cast <unknown_abi*>(implemented_interfaces<T>::find (obj, iid_finder{ iid }));
392+ return static_cast <unknown_abi*>(implemented_interfaces<T>::find (find_iid_traits<T>{ obj, iid }));
380393 }
381394
382- struct inspectable_finder
395+ template <typename I>
396+ struct has_interface_traits
383397 {
398+ template <typename T>
399+ constexpr bool test () const noexcept
400+ {
401+ return std::is_same_v<T, I>;
402+ }
403+
404+ template <typename >
405+ static constexpr bool found () noexcept
406+ {
407+ return true ;
408+ }
409+
410+ static constexpr bool not_found () noexcept
411+ {
412+ return false ;
413+ }
414+ };
415+
416+ template <typename T, typename I>
417+ constexpr bool has_interface () noexcept
418+ {
419+ return impl::implemented_interfaces<T>::find (has_interface_traits<I>{});
420+ }
421+
422+ template <typename T>
423+ struct find_inspectable_traits
424+ {
425+ T const * m_object;
426+
384427 template <typename I>
385428 static constexpr bool test () noexcept
386429 {
387430 return std::is_base_of_v<inspectable_abi, abi_t <I>>;
388431 }
432+
433+ template <typename I>
434+ constexpr void * found () const noexcept
435+ {
436+ return to_abi<I>(m_object);
437+ }
438+
439+ static constexpr void * not_found () noexcept
440+ {
441+ return nullptr ;
442+ }
389443 };
390444
391445 template <typename T>
392- inspectable_abi* find_inspectable (const T * obj) noexcept
446+ inspectable_abi* find_inspectable (T const * obj) noexcept
393447 {
394448 using default_interface = typename implements_default_interface<T>::type;
395449
@@ -399,7 +453,7 @@ namespace winrt::impl
399453 }
400454 else
401455 {
402- return static_cast <inspectable_abi*>(implemented_interfaces<T>::find (obj, inspectable_finder{ }));
456+ return static_cast <inspectable_abi*>(implemented_interfaces<T>::find (find_inspectable_traits<T>{ obj }));
403457 }
404458 }
405459
@@ -502,7 +556,7 @@ namespace winrt::impl
502556 template <typename D>
503557 struct produce <D, INonDelegatingInspectable> : produce_base<D, INonDelegatingInspectable>
504558 {
505- int32_t __stdcall QueryInterface (const guid& id, void ** object) noexcept final
559+ int32_t __stdcall QueryInterface (guid const & id, void ** object) noexcept final
506560 {
507561 return this ->shim ().NonDelegatingQueryInterface (id, object);
508562 }
@@ -910,7 +964,7 @@ namespace winrt::impl
910964 return target;
911965 }
912966
913- int32_t __stdcall NonDelegatingQueryInterface (const guid& id, void ** object) noexcept
967+ int32_t __stdcall NonDelegatingQueryInterface (guid const & id, void ** object) noexcept
914968 {
915969 if (is_guid_of<Windows::Foundation::IInspectable>(id) || is_guid_of<Windows::Foundation::IUnknown>(id))
916970 {
@@ -932,13 +986,13 @@ namespace winrt::impl
932986
933987 int32_t __stdcall NonDelegatingGetIids (uint32_t * count, guid** array) noexcept
934988 {
935- const auto & local_iids = static_cast <D*>(this )->get_local_iids ();
936- const uint32_t & local_count = local_iids.first ;
989+ auto const & local_iids = static_cast <D*>(this )->get_local_iids ();
990+ uint32_t const & local_count = local_iids.first ;
937991 if constexpr (root_implements_type::is_composing)
938992 {
939993 if (local_count > 0 )
940994 {
941- const com_array<guid>& inner_iids = get_interfaces (root_implements_type::m_inner);
995+ com_array<guid> const & inner_iids = get_interfaces (root_implements_type::m_inner);
942996 *count = local_count + inner_iids.size ();
943997 *array = static_cast <guid*>(WINRT_IMPL_CoTaskMemAlloc (sizeof (guid)*(*count)));
944998 if (*array == nullptr )
@@ -1189,7 +1243,7 @@ namespace winrt::impl
11891243 }
11901244
11911245 virtual unknown_abi* get_unknown () const noexcept = 0 ;
1192- virtual std::pair<uint32_t , const guid*> get_local_iids () const noexcept = 0 ;
1246+ virtual std::pair<uint32_t , guid const *> get_local_iids () const noexcept = 0 ;
11931247 virtual hstring GetRuntimeClassName () const = 0 ;
11941248 virtual void * find_interface (guid const &) const noexcept = 0 ;
11951249 virtual inspectable_abi* find_inspectable () const noexcept = 0 ;
@@ -1450,7 +1504,7 @@ WINRT_EXPORT namespace winrt
14501504 return impl::find_inspectable (static_cast <const D*>(this ));
14511505 }
14521506
1453- std::pair<uint32_t , const guid*> get_local_iids () const noexcept override
1507+ std::pair<uint32_t , guid const *> get_local_iids () const noexcept override
14541508 {
14551509 using interfaces = impl::uncloaked_interfaces<D>;
14561510 using local_iids = impl::uncloaked_iids<interfaces>;
0 commit comments