Code: Alles auswählen
for(auto x=0u; x<X; ++x)
for(auto y=0u; y<Y; ++y)
for(auto z=0u; z<Z; ++z)
Something(x,y,z);
Code: Alles auswählen
for(auto& i : Range3d(2, 2, 2))
{
cout << i.x << "/" << i.y << "/" << i.z << endl;
}
Code: Alles auswählen
class Range3d
{
public:
Range3d(unsigned int x, unsigned int y, unsigned int z):
Range3d(uvec3(x, y, z)) {};
Range3d(uvec3 range):
range(range),
position(0, 0, 0)
{
}
Range3d begin()
{
return *this;
}
Range3d end()
{
return *this;
}
bool operator!= (Range3d r)
{
// r should always be *this
return uvec3(position.x+1, position.y+1, position.z+1) != r.range;
}
Range3d& operator++ ()
{
position.x++;
if(position.x==range.x)
{
position.x=0;
position.y++;
if(position.y==range.y)
{
position.y=0;
position.z++;
// z should never overflow due to loop exit condition
}
}
return *this;
}
uvec3 operator* ()
{
return position;
}
private:
uvec3 range;
uvec3 position;
};