{"id":1293,"date":"2013-07-30T14:47:00","date_gmt":"2013-07-30T14:47:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2013\/07\/30\/new-features-in-ccxs-collection-h-for-vs-2013-rtm\/"},"modified":"2019-02-18T18:40:58","modified_gmt":"2019-02-18T18:40:58","slug":"new-features-in-ccxs-collection-h-for-vs-2013-rtm","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/new-features-in-ccxs-collection-h-for-vs-2013-rtm\/","title":{"rendered":"New Features in C++\/CX&#039;s &#060;collection.h&#062; for VS 2013 RTM"},"content":{"rendered":"<div>\n<h2>Introduction:<\/h2>\n<p>Hi, I&rsquo;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&rsquo;s <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/hh710418(v=vs.120).aspx\">&lt;collection.h&gt;<\/a>. It was certainly an honor to be one of the few to contribute to &lt;collection.h&gt;. You can find these changes in VS 2013 RTM (these changes are not in 2013 Preview).<\/p>\n<p>&nbsp;<\/p>\n<div>\n<h2>Summary:<\/h2>\n<\/div>\n<p>These are the changes I&rsquo;ve made to &lt;collection.h&gt;:<\/p>\n<p>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Added UnorderedMap and UnorderedMapView&nbsp;wrapper classes to &lt;collection.h&gt;.<\/p>\n<p>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Added initializer_list constructors to Vector, VectorView, Map, MapView, &nbsp;UnorderedMap,&nbsp;and UnorderedMapView.<\/p>\n<p>3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Added validation so that customers use valid WinRT types to instantiate the collections in &lt;collection.h&gt;.<\/p>\n<p>&nbsp;<\/p>\n<div>\n<h2>Features:<\/h2>\n<\/div>\n<p>UnorderedMap and&nbsp;UnorderedMapView:<\/p>\n<p>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, &nbsp;UnorderedMap and&nbsp;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&nbsp;UnorderedMapView by providing your own predicates.<\/p>\n<p>&nbsp;<\/p>\n<p>initializer_list constructors:<\/p>\n<p>You can now construct any data structure using the C++11 initializer_list constructors.<\/p>\n<p>An example:<\/p>\n<p><span style=\"font-family: 'courier new', courier\">namespace WFC = Windows::Foundation::Collections;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier\">namespace PC = Platform::Collections;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier\">WFC::IVector&lt;int&gt;^ v = ref new PC::Vector&lt;int&gt;{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier\">WFC::IMap&lt;int, int&gt;^ m<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier\">= ref new PC::Map&lt;int, int&gt;{ { 1, 10 }, { 2, 20 }, { 3, 30 }, { 4, 40 } };<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier\">WFC::IMap&lt;int, int&gt;^ m2<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier\">= ref new PC::UnorderedMap&lt;int, int&gt;{ { 1, 10 }, { 2, 20 }, { 3, 30 }, { 4, 40 } };<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>Valid WinRT types only:<\/p>\n<p>We now check whether the type you want to store in your given data structure is a valid WinRT type. Currently if you have:<\/p>\n<p><span style=\"font-family: 'courier new', courier\">PC::Vector&lt;ordinary_cpp_class&gt;<\/span><\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>Valid WinRT types are:<\/p>\n<ol>\n<li>integers<\/li>\n<li>interface class ^<\/li>\n<li>public ref class^<\/li>\n<li>value struct<\/li>\n<li>public enum class<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Thank you for taking the time and reading this post,<\/p>\n<p>Brandon Jacobs<\/p>\n<p>SDE Intern &ndash; Visual C++ Libraries<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Hi, I&rsquo;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&rsquo;s &lt;collection.h&gt;. It was certainly an honor to be one of the few to contribute to &lt;collection.h&gt;. You can find these changes in VS 2013 RTM (these [&hellip;]<\/p>\n","protected":false},"author":273,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[121,201],"class_list":["post-1293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-ccx","tag-collection-h"],"acf":[],"blog_post_summary":"<p>Introduction: Hi, I&rsquo;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&rsquo;s &lt;collection.h&gt;. It was certainly an honor to be one of the few to contribute to &lt;collection.h&gt;. You can find these changes in VS 2013 RTM (these [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/273"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=1293"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/1293\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=1293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=1293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=1293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}