Skip to content
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

Enable WINRT_LEAN_AND_MEAN #15215

Merged
merged 5 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
21 changes: 21 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
#include "CommandPalette.g.h"
#include "AppCommandlineArgs.h"

struct hash_winrt_object_as_pointer
{
size_t operator()(const ::winrt::Windows::Foundation::IUnknown& value) const noexcept
{
void* const abi_value = winrt::get_abi(value.try_as<::winrt::Windows::Foundation::IUnknown>());
return std::hash<void*>{}(abi_value);
}
Copy link
Member

Choose a reason for hiding this comment

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

The extra try_as seems redundant? It might make sense to do

size_t operator()(const auto& value) const noexcept
{
    return std::hash<void*>{}(winrt::get_abi(value));
}

or alternatively

size_t operator()(const auto& value) const noexcept
{
    return til::hash(winrt::get_abi(value));
}

Due to the novel design choices in std::unordered_map I suspect there's not a particularly big difference between the two though, so I don't think it matters what you pick.

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh. I copied this directly out of winrt/base.h.

};

namespace std
{
template<>
struct hash<::winrt::Windows::UI::Xaml::DataTemplate> : public hash_winrt_object_as_pointer
{
};
template<>
struct hash<::winrt::Windows::UI::Xaml::Controls::Primitives::SelectorItem> : public hash_winrt_object_as_pointer
{
};
}
Copy link
Member

@lhecker lhecker Apr 21, 2023

Choose a reason for hiding this comment

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

You can also just pass hash_winrt_object_as_pointer directly as a trailing template parameter to the two hashmaps. That would seem cleaner to me. With using statements you can make the template names a bit shorter.

Copy link
Member Author

Choose a reason for hiding this comment

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

that's fair. i was going for "maximal equivalence in minimal lines deleted". I'll probably move over to this


// fwdecl unittest classes
namespace TerminalAppLocalTests
{
Expand Down
2 changes: 2 additions & 0 deletions src/cppwinrt.build.pre.props
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<DisableSpecificWarnings>5104;28204;%(DisableSpecificWarnings)</DisableSpecificWarnings>

<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>

<PreprocessorDefinitions>WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem Condition="'%(SubSystem)'==''">Console</SubSystem>
Expand Down