-
Notifications
You must be signed in to change notification settings - Fork 281
feat: add make_array_of_(uuid|guid) #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2e5346b
960310f
e363b7c
bd7d9a6
e080b13
b41ab25
c758246
229a503
16a2471
04511fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,13 +175,13 @@ unique_com_class_object_cookie | |
| template <typename... Ts> | ||
| WI_NODISCARD_REASON("The classes are unregistered when the returned value is destructed") | ||
| std::vector<unique_com_class_object_cookie> register_com_server( | ||
| std::array<GUID, sizeof...(Ts)> const& guids, DWORD context = CLSCTX_LOCAL_SERVER, DWORD flags = REGCLS_MULTIPLEUSE) | ||
| std::array<GUID, sizeof...(Ts)> const& clsids, DWORD context = CLSCTX_LOCAL_SERVER, DWORD flags = REGCLS_MULTIPLEUSE) | ||
| { | ||
| std::vector<wil::unique_com_class_object_cookie> registrations; | ||
| registrations.reserve(sizeof...(Ts)); | ||
|
|
||
| std::size_t i = 0; | ||
| (registrations.push_back(wil::register_com_server<Ts>(guids[i++], context, flags | REGCLS_SUSPENDED)), ...); | ||
| (registrations.push_back(wil::register_com_server<Ts>(clsids[i++], context, flags | REGCLS_SUSPENDED)), ...); | ||
|
|
||
| // allow the user to keep class objects suspended if they've explicitly passed REGCLS_SUSPENDED. | ||
| if (!WI_IsFlagSet(flags, REGCLS_SUSPENDED)) | ||
|
|
@@ -192,6 +192,54 @@ std::vector<unique_com_class_object_cookie> register_com_server( | |
| return registrations; | ||
| } | ||
|
|
||
| template <typename... Types> | ||
| struct clsid_array | ||
| { | ||
| std::array<GUID, sizeof...(Types)> value; | ||
| explicit clsid_array(std::array<GUID, sizeof...(Types)> value) : value(std::move(value)) | ||
| { | ||
| } | ||
| }; | ||
|
|
||
| template <typename... Ts> | ||
| WI_NODISCARD_REASON("The classes are unregistered when the returned value is destructed") | ||
| std::vector<unique_com_class_object_cookie> register_com_server( | ||
| wil::clsid_array<Ts...> const& clsids, DWORD context = CLSCTX_LOCAL_SERVER, DWORD flags = REGCLS_MULTIPLEUSE) | ||
| { | ||
| return register_com_server<Ts...>(clsids.value, context, flags); | ||
| } | ||
|
|
||
| namespace details | ||
| { | ||
| template <typename T> | ||
| struct has_iid | ||
| { | ||
| template <typename U = T, std::enable_if_t<std::is_same_v<GUID, std::decay_t<decltype(__uuidof(U))>>, int> = 0> | ||
| static std::true_type invoke(int); | ||
|
|
||
| template <typename U = T> | ||
| static std::false_type invoke(float); | ||
|
|
||
| static constexpr bool value = decltype(invoke(0))::value; | ||
| }; | ||
|
|
||
| template <typename T> | ||
| constexpr bool has_iid_v = has_iid<T>::value; | ||
| } | ||
|
|
||
| template <typename... Types> | ||
| constexpr auto make_array_of_uuid() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I like the names
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Seems dunhor's suggestion can answer the question? I'd expect user typing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. guid/uuid are the most generic. clsid and iid are specializations. these are all aliases for the same thing, so using different names can be dangerous due to the false sense of type safety. |
||
| { | ||
| return clsid_array<Types...>{std::array<GUID, sizeof...(Types)>{__uuidof(Types)...}}; | ||
| } | ||
|
|
||
| template <typename... Types> | ||
| constexpr auto make_array_of_guid() | ||
| { | ||
| static_assert(!(... && details::has_iid_v<Types>), "Use make_array_of_uuid for COM class instead"); | ||
| return clsid_array<Types...>{std::array<GUID, sizeof...(Types)>{winrt::guid_of<Types>()...}}; | ||
| } | ||
|
|
||
| #endif // (!defined(__WIL_CPPWINRT_AUTHORING_INCLUDED_COM_SERVER) && defined(__WIL_CPPWINRT_AUTHORING_INCLUDED_ICLASSFACTORY) && defined(_COMBASEAPI_H_)) | ||
|
|
||
| #if (!defined(__WIL_CPPWINRT_AUTHORING_INCLUDED_FOUNDATION) && defined(WINRT_Windows_Foundation_H)) || \ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the pattern here is "copy then move". In practice this value is always move-constructed from temporary, or in more recent standard just materialized without any temporary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::moveis pointless here. It's astd::arrayandGUIDs. Accept byconstreference and just assign and make itconstexprwhile you are at it.