I'm moving with the times and thought I should start a new project with the goal to use and expose myself to smart pointers more. I'm thinking of a large pool of unique_ptrs storing collision components. These components will be passed by const ref to a quad tree that internally perform read-only ops on the ptrs.
I've written a simplified example to reflect the intentions of my implementation.
struct Owner
{
unique_ptr<int> uPtr;
};
struct SomeContainer
{
list<const unique_ptr<int>*> uPtrList;
void Insert( const unique_ptr<int>& borrowedUPtr )
{
list.push_back( &borrowedUPtr );
}
void DoSomething()
{
for( const auto& ptr : uPtrList )
// Perform read ops
}
};
These are my intentions:
Owner owns the unique_ptr and thereby controls its lifetime.
SomeContainer will store a const reference to the pointer since it's not permitted to neither reset nor modify the pointer in any way.
Is this a viable approach or am I disturbing the force?