|
Re: Should we use std::unique_ptr?
We also started using smart pointers in WPILib so we could express ownership semantics. As the name implies, std::unique_ptr represents an object with one owner.
Since no one has mentioned this yet, I'll point out that a raw pointer is the non-owning counterpart of std::unique_ptr (which can be obtained via get()). Given those semantics, Requires() takes a non-owning reference to a subsystem because subsystem lifetime is a strict superset of command lifetime.
By the way, shared ownership is represented by std::shared_ptr and std::weak_ptr for owning and non-owning references respectively.
|