ATL collection classes did not receive an update related to new C++11 range-based fors and other fancy features. Well it’s a pity because writing
for(auto&& pPin: AudioPinList)
pPin-> //...
compared to
for(POSITION Position = AudioPinList.GetHeadPosition(); Position; AudioPinList.GetNext(Position))
{
IPin* pPin = AudioPinList.GetAt(Position);
pPin-> //...
is indeed a relief. Namespace std 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.
CRoIterativeCollectionTclass is a traits-based uniform base for lists and arrays, adding (again, uniform) helpers to iterate through collection:GetCountThat,GetThat,RemoveThat,RemoveFirst,RemoveLastFind,FindThat,FindFirst,FindLast,FindFirstThat,FindLastThatForEachbegin,endimplementing for range based for loops
CRoArrayTis a class extendingCAtlArray, adding mentioned above through inheriting fromCRoIterativeCollectionTCRoListTis a class extendingCAtlList, adding mentioned above through inheriting fromCRoIterativeCollectionTCRoAssignableListT,CRoAssignableArrayT,CRoAssignableMapTto 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 copiesCRoFixedArrayT,CRoFixedMapTare 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)CRoMapTis essentially an thin extension ofCAtlMap, however also addsGetPositions()andGetValues()methods, which can be used for range-based for loops
Download
- Header file: roatlcollections.h