Archive 17/01/2023.

C++11 generic for loop

setzer22

I’ve just realised that the generic container classes in urho (like Vector) support Iterators but not generic for loops from C++11. Is there a reason to not support them? Just to be clear by generic for loops I mean:

Vector<SomeObject> v;

//v is filled...

for(SomeObject obj : v) {
    //treat obj as you would treat v[i] in a normal for loop
}

Thanks!

cadaver

Due to the coding convention (eg. uppercase functions) the iterators are not compatible with STL and therefore not directly compatible with C++11 generic loops.

It’s not exactly the same, but there’s an optional include file ForEach.h in Source/Engine/Container which defines a foreach macro you can use.

shu

Wouldn’t it make sense to make an exception of the Uppercase convention in this case and just add lowercase functions (begin(), end()) so that the compiler can use the urho container types too?

I think it’s much nicer to write

than

Stinkfist

The begin() and end() overloads for Urho containers would be nice indeed. See related discussion here: github.com/urho3d/Urho3D/issues/561

cadaver

Is now in. The old foreach solution is still used on VS2010, as generic for is not available.