Introduction:
Hi, I’m Brandon Jacobs, an intern on the Visual C++ Libraries team. For part of my internship, I was tasked with adding new features to Stephan T. Lavavej’s
Summary:
These are the changes I’ve made to
1. Added UnorderedMap and UnorderedMapView wrapper classes to
2. Added initializer_list constructors to Vector, VectorView, Map, MapView, UnorderedMap, and UnorderedMapView.
3. Added validation so that customers use valid WinRT types to instantiate the collections in
Features:
UnorderedMap and UnorderedMapView:
This is the wrapper class for the std::unordered_map class. The functionality is the same as Map and MapView. The only difference is the underlying data structure, which is a hash table instead of a balanced binary tree. So, types must be hashable and must be able to show equality. Just like Map and MapView defaults to std::less, UnorderedMap and UnorderedMapView defaults to std::hash and std::equal_to. Both the hash and equality predicates are template parameters, so you are allowed to change the actions of UnorderedMap and UnorderedMapView by providing your own predicates.
initializer_list constructors:
You can now construct any data structure using the C++11 initializer_list constructors.
An example:
namespace WFC = Windows::Foundation::Collections;
namespace PC = Platform::Collections;
WFC::IVector
WFC::IMap
= ref new PC::Map
WFC::IMap
= ref new PC::UnorderedMap
Valid WinRT types only:
We now check whether the type you want to store in your given data structure is a valid WinRT type. Currently if you have:
PC::Vector
You will get an odd compiler error. Now we check whether the types passed in are valid WinRT types. If this check fails, you will now get a much nicer compiler error that even includes the line in which you tried to create a collection with an invalid type.
Only the items that will appear in the Windows::Foundation::Collections interfaces need to be valid WinRT types. Predicates such as std::less, std::hash, etc. are not passed into the Windows::Foundation::Collections interfaces, so they are not affected by that restriction.
Valid WinRT types are:
- integers
- interface class ^
- public ref class^
- value struct
- public enum class
Thank you for taking the time and reading this post,
Brandon Jacobs
SDE Intern – Visual C++ Libraries