#pragma once #include class Cuboid { private: const std::array _size; const std::size_t _volume; public: Cuboid(std::size_t nX, std::size_t nY, std::size_t nZ): _size{nX, nY, nZ}, _volume(nX*nY*nZ) { } std::size_t volume() const { return _volume; } std::size_t index(unsigned iX, unsigned iY, unsigned iZ) const { return iX*_size[1]*_size[2] + iY*_size[2] + iZ; } int operator[](unsigned i) const { return _size[i]; } template void traverse(F f) { for (int iX = 0; iX < _size[0]; ++iX) { for (int iY = 0; iY < _size[1]; ++iY) { for (int iZ = 0; iZ < _size[2]; ++iZ) { f(iX, iY, iZ, index(iX,iY,iZ)); } } } } };