We are passing around a lot of pointers, smart pointers or const references to cubes in our code. This is necessary, as it's a major part of our engine. For example I'm working on the new octree collision (see upcoming pull request later) which looks like this:
So in this code I am passing the cube as std::shared_ptr. This is fine, but clang-tidy suggests to pass it as const reference to a shared pointer. Jason Turner and Scott Meyers however say that this is not a good idea.
We have the following options:
Pass it as const reference
Pass it as a raw pointer
Pass it as a std::shared_ptr
Pass it as a std::weak_ptr
Notes:
We do not want to transfer ownership of the cube, so passing by value and using std::move is not an option in my opinion.
Copying data could be costly
We need to copy the data though, because if we pass it as const reference, the data could become invalid while the function body is being executed.
I think this is a common question which will is relevant for many code parts.
What do you guys propose?
We are passing around a lot of pointers, smart pointers or const references to cubes in our code. This is necessary, as it's a major part of our engine. For example I'm working on the new octree collision (see upcoming pull request later) which looks like this:
So in this code I am passing the cube as std::shared_ptr. This is fine, but clang-tidy suggests to pass it as const reference to a shared pointer. Jason Turner and Scott Meyers however say that this is not a good idea.
We have the following options:
std::shared_ptr
std::weak_ptr
Notes:
I think this is a common question which will is relevant for many code parts. What do you guys propose?