Archive 17/01/2023.

[Solved] Provide lower-case begin() and end()

Enhex

…so range-based for loops can be used.
You can have both lowercase and uppercase version if it’s so important.

I’ve been told about ForEach.h on the IRC but it completely defeats the purpose of range-based loops which is to make simple things simple, not more complex.

cadaver

What is the problem with ForEach.h? It defines std::begin, std::end free functions that work with the Urho containers, after which you should be able to use range-based for.

Another possibility is of course to move the free functions into the header files of vector, hashmap etc. after which including ForEach.h would become unnecessary.

Enhex

I can’t find an example or instructions of how to use it.
For me the solution was to switch to std containers.

Stinkfist
#include <Urho3D/Container/ForEach.h>
#include <Urho3D/Container/Vector.h>
// ...
Urho3D::Vector<int> values;
values.Push(1);
// Push more...
for(auto v : values)
    // ...
cadaver

I will move the std::begin() / std::end() to the respective headers, after which you should only need to include ForEach.h if you use the macro (and the legacy hack for VS2010 support)

darkhog

Do you need performance that badly? If not maybe you should use Lua instead of C++?

Stinkfist

Thread should be tagged as [SOLVED] BTW.