Open jpj-verstappen opened 4 years ago
This just works with begin()
and end()
.
Here is an example:
CTypedPtrArray<CObArray, IntObject*> arr;
arr.Add(new IntObject(1));
arr.Add(new IntObject(3));
arr.Add(new IntObject(5));
arr.Add(new IntObject(7));
bool all = std::all_of(begin(arr), end(arr),
[](IntObject* o) { return o->value % 2 == 1; });
Assert::IsTrue(all);
for (auto p : arr)
delete p;
where IntObject
is
struct IntObject : CObject
{
int value;
explicit IntObject(int const v) noexcept : value(v) {}
explicit operator int()
{
return value;
}
};
You can find examples in the unit tests project.
Nice work on the range based for loops! Working like a charm. I would like to use the MFC collection classes in the std algorithms, like std::all_of. Looks like I need an iterator for the begin and the end of the array I'm using (CTypedPtrArray). Can someone give an example of how to implement this?
Usage example: