...
So that not save a raw pointer in vector or other containers.
1.2 Using factory creators instead of new
In order to force the smart ptr usage, the developer could add macro ENABLE_FACTORY_CREATOR to class
like:
If you add this macro to the class, then we could make sure the smart ptr is used for our class.
Block* block = new Block(xxxx); // compile error during build
Block block(xxx); // it is ok
std::shared_ptr<Block> block = Block::create_shared(xxxx); // it is ok
std::unique_ptr<Block> block = Block::create_unique(xxxx); // it is ok
1.3 Lock and Unlock
There are many lock and unlock code. Could not make sure that the lock is correctly released. Should use unique lock or lock guard. For example, in following example, the lock is conditionally locked by checking acquire_lock
...