Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions include/wil/cppwinrt_authoring.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,16 @@ unique_com_class_object_cookie
return registration;
}

template <typename... Types>
struct clsid_array
{
std::array<GUID, sizeof...(Types)> 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)
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>(clsids.value[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))
Expand All @@ -198,6 +192,23 @@ 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))
Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::move is pointless here. It's a std::array and GUIDs. Accept by const reference and just assign and make it constexpr while you are at it.

{
}
};

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>
Expand Down
88 changes: 44 additions & 44 deletions tests/ComApartmentVariableTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,49 +363,49 @@ TEST_CASE("ComApartmentVariable::ShutdownRegistration", "[LocalOnly][com][unique
}
}

TEST_CASE("ComApartmentVariable::CallAllMethods", "[com][apartment_variable]")
{
RunApartmentVariableTest(TestApartmentVariableAllMethods<mock_platform>);
}

TEST_CASE("ComApartmentVariable::GetOrCreateForms", "[com][apartment_variable]")
{
RunApartmentVariableTest(TestApartmentVariableGetOrCreateForms<mock_platform>);
}

TEST_CASE("ComApartmentVariable::VariableLifetimes", "[com][apartment_variable]")
{
RunApartmentVariableTest(TestApartmentVariableLifetimes<mock_platform>);
}

TEST_CASE("ComApartmentVariable::WinningApartmentAlreadyRundownRace", "[com][apartment_variable]")
{
RunApartmentVariableTest(TestWinningApartmentAlreadyRundownRace<mock_platform>);
}

TEST_CASE("ComApartmentVariable::LosingApartmentAlreadyRundownRace", "[com][apartment_variable]")
{
RunApartmentVariableTest(TestLosingApartmentAlreadyRundownRace<mock_platform>);
}

TEST_CASE("ComApartmentVariable::MultipleApartments", "[com][apartment_variable]")
{
RunApartmentVariableTest(TestMultipleApartments<mock_platform>);
}

TEST_CASE("ComApartmentVariable::UseRealPlatformRunAllTests", "[com][apartment_variable]")
{
if (!wil::are_apartment_variables_supported())
{
return;
}

RunApartmentVariableTest(TestApartmentVariableAllMethods);
RunApartmentVariableTest(TestApartmentVariableGetOrCreateForms);
RunApartmentVariableTest(TestApartmentVariableLifetimes);
RunApartmentVariableTest(TestWinningApartmentAlreadyRundownRace);
RunApartmentVariableTest(TestLosingApartmentAlreadyRundownRace);
RunApartmentVariableTest(TestMultipleApartments);
}
//TEST_CASE("ComApartmentVariable::CallAllMethods", "[com][apartment_variable]")
//{
// RunApartmentVariableTest(TestApartmentVariableAllMethods<mock_platform>);
//}
//
//TEST_CASE("ComApartmentVariable::GetOrCreateForms", "[com][apartment_variable]")
//{
// RunApartmentVariableTest(TestApartmentVariableGetOrCreateForms<mock_platform>);
//}
//
//TEST_CASE("ComApartmentVariable::VariableLifetimes", "[com][apartment_variable]")
//{
// RunApartmentVariableTest(TestApartmentVariableLifetimes<mock_platform>);
//}
//
//TEST_CASE("ComApartmentVariable::WinningApartmentAlreadyRundownRace", "[com][apartment_variable]")
//{
// RunApartmentVariableTest(TestWinningApartmentAlreadyRundownRace<mock_platform>);
//}
//
//TEST_CASE("ComApartmentVariable::LosingApartmentAlreadyRundownRace", "[com][apartment_variable]")
//{
// RunApartmentVariableTest(TestLosingApartmentAlreadyRundownRace<mock_platform>);
//}
//
//TEST_CASE("ComApartmentVariable::MultipleApartments", "[com][apartment_variable]")
//{
// RunApartmentVariableTest(TestMultipleApartments<mock_platform>);
//}
//
//TEST_CASE("ComApartmentVariable::UseRealPlatformRunAllTests", "[com][apartment_variable]")
//{
// if (!wil::are_apartment_variables_supported())
// {
// return;
// }
//
// RunApartmentVariableTest(TestApartmentVariableAllMethods);
// RunApartmentVariableTest(TestApartmentVariableGetOrCreateForms);
// RunApartmentVariableTest(TestApartmentVariableLifetimes);
// RunApartmentVariableTest(TestWinningApartmentAlreadyRundownRace);
// RunApartmentVariableTest(TestLosingApartmentAlreadyRundownRace);
// RunApartmentVariableTest(TestMultipleApartments);
//}

#endif