{"id":1540,"date":"2015-05-30T14:41:11","date_gmt":"2015-05-30T12:41:11","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1540"},"modified":"2015-05-29T17:44:41","modified_gmt":"2015-05-29T15:44:41","slug":"range-based-for-with-atl-collections","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1540","title":{"rendered":"Range-based for with ATL Collections"},"content":{"rendered":"<p>ATL collection classes did not receive an update related to new <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/range-for\">C++11 range-based <code>for<\/code>s<\/a> and other fancy features. Well it&#8217;s a pity because writing<\/p>\n<pre><code>for(auto&amp;&amp; pPin: AudioPinList)\r\n  pPin-&gt; \/\/...\r\n<\/code><\/pre>\n<p>compared to<\/p>\n<pre><code>for(POSITION Position = AudioPinList.GetHeadPosition(); Position; AudioPinList.GetNext(Position))\r\n{\r\n  IPin* pPin = AudioPinList.GetAt(Position);\r\n  pPin-&gt; \/\/...\r\n<\/code><\/pre>\n<p>is indeed a relief. Namespace <code>std<\/code> is, of course, good but ATL is still here as well. Here is a take on adding range-based for loops to ATL collection classes.<\/p>\n<ul>\n<li><code>CRoIterativeCollectionT<\/code> class is a traits-based uniform base for lists and arrays, adding (again, uniform) helpers to iterate through collection:\n<ul>\n<li><code>GetCountThat<\/code>, <code>GetThat<\/code>, <code>RemoveThat<\/code>, <code>RemoveFirst<\/code>, <code>RemoveLast<\/code><\/li>\n<li><code>Find<\/code>, <code>FindThat<\/code>, <code>FindFirst<\/code>, <code>FindLast<\/code>, <code>FindFirstThat<\/code>, <code>FindLastThat<\/code><\/li>\n<li><code>ForEach<\/code><\/li>\n<li><code>begin<\/code>, <code>end<\/code> implementing for range based for loops<\/li>\n<\/ul>\n<\/li>\n<li><code>CRoArrayT<\/code> is a class extending <code>CAtlArray<\/code>, adding mentioned above through inheriting from <code>CRoIterativeCollectionT<\/code><\/li>\n<li><code>CRoListT<\/code> is a class extending <code>CAtlList<\/code>, adding mentioned above through inheriting from <code>CRoIterativeCollectionT<\/code><\/li>\n<li><code>CRoAssignableListT<\/code>, <code>CRoAssignableArrayT<\/code>, <code>CRoAssignableMapT<\/code> to inherit collections and allow assignment operators on those (through duplication of elements), esp. to be able to easily put the collections as members of classes, eligible for assignment operator copies<\/li>\n<li><code>CRoFixedArrayT<\/code>, <code>CRoFixedMapT<\/code> are compatible collection classes backed by stack memory only, no allocations (old stuff as is, was used somewhere in handler where immediate response assumed no memory allocation operations)<\/li>\n<li><code>CRoMapT<\/code> is essentially an thin extension of <code>CAtlMap<\/code>, however also adds <code>GetPositions()<\/code> and <code>GetValues()<\/code> methods, which can be used for range-based for loops<\/li>\n<\/ul>\n<h3>Download<\/h3>\n<ul>\n<li>Header file: <a href=\"https:\/\/www.alax.info\/trac\/public\/browser\/trunk\/Common\/alax.info\/roatlcollections.h\">roatlcollections.h<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>ATL collection classes did not receive an update related to new C++11 range-based fors and other fancy features. Well it&#8217;s a pity because writing for(auto&amp;&amp; pPin: AudioPinList) pPin-&gt; \/\/&#8230; compared to for(POSITION Position = AudioPinList.GetHeadPosition(); Position; AudioPinList.GetNext(Position)) { IPin* pPin = AudioPinList.GetAt(Position); pPin-&gt; \/\/&#8230; is indeed a relief. Namespace std is, of course, good but&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1540\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[487,480,479,481],"class_list":["post-1540","post","type-post","status-publish","format-standard","hentry","category-atl","tag-atl","tag-c11","tag-collection","tag-range-for"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1540"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1540\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}