Add option to strip our rarely used C++/WinRT templates and traits #613
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are a few areas where C++/WinRT provides "helpful" templates and traits, but some of these are rarely used and add a significant expense to compilation time. They cannot simply be removed without potentially breaking existing code. For now, I'm providing the option to remove them by defining
WINRT_LEAN_AND_MEAN. If subsequent testing reveals that this can be broadly applied then this may be "turned on" for everyone at some future point. DefiningWINRT_LEAN_AND_MEANimpacts three areas.Variable templates are used to make
winrt::name_of<T>()work with all WinRT types while WinRT itself only requires the names of WinRT classes, structs, and enums. This leaves a huge amount of WinRT interface and delegate names that go unused. DefiningWINRT_LEAN_AND_MEANwill strip out the variable template specializations for WinRT interfaces and delegates.std::hash<T>specializations are provided for all WinRT classes and interfaces on the assumption that someone might want to use such types as the key for astd::unordered_map<K, V>. However, this is rarely used and developers can easily provide a hashing function for the odd type they actually use. DefiningWINRT_LEAN_AND_MEANwill strip out the specializations for WinRT classes and interfaces.C++/WinRT allows any WinRT interface to be used or called as well as to be implemented. Some WinRT interfaces are however exclusive to a given WinRT class and should not be implemented by any other object. C++/WinRT allowed this to accommodate implementing WinRT classes, but it leaves a great many internal class template specializations defined that hardly any project using C++/WinRT will ever implement. Defining
WINRT_LEAN_AND_MEANwill strip out the specializations of exclusive interfaces that are not implemented by the project. Non-exclusive interfaces remain available for all to implement.Defining
WINRT_LEAN_AND_MEANshaves more than 10% off the size of my large test PCH. Again, this is an opt-in for the moment. To receive this benefit you need to defineWINRT_LEAN_AND_MEANbefore including any C++/WinRT headers.Fixes #612