vulkan-renderer
vulkan-renderer copied to clipboard
Throw an exception if somebody tries to access childs() on a cube which has no childs
const auto world = std::make_shared<world::Cube>(world::Cube::Type::EMPTY, 1.0f, glm::vec3{0, 0, 0});
// uh oh
world->childs()[3]->set_type(world::Cube::Type::EMPTY);
Not sure if we really require an exception here. Also you can use at https://en.cppreference.com/w/cpp/container/array/at.
I would consider this as an intended behaviour.
One the one hand you are right, since those methods actually belong to performance critical code. On the other hand .at would not prevent us from sccessing the methods of instances which do not exist, which would throw an exception anyways.
On the other hand .at would not prevent us from sccessing the methods of instances which do not exist, which would throw an exception anyways.
childs() is noexcept actually, it is just a getter.
On the other hand .at would not prevent us from sccessing the methods of instances which do not exist
It will as it will throw an Out of Bounds Exception. The given child array is empty.