Migrate C++ command-based to use unique_ptr
semantics
#4303
Labels
component: command-based
WPILib Command Based Library
type: discussion
Questions, proposals and info that requires discussion.
This is mostly a change in documentation/recommended usage.
The current (value) semantics of C++ command-based cause object slicing, which is difficult for both team and WPILib code. For decorators, there's an elaborate CRTP hack set up. That doesn't teams who need to specify the precise type of the command (which can change) to avoid object slicing.
Alternate options:
shared_ptr
has synchronization functionality we don't need, andunique_ptr
fits the ownership model and semantics we want.The only problem is that it uses
->
instead of.
, but that's what docs are for. Factories should hide themake_unique
call.The scheduler should still use plain pointers internally, and schedule/button bindings can take the underlying pointer from a
unique_ptr<Command>&
parameter.Perhaps leave an opening so that teams who prefer different semantics can use them?
The text was updated successfully, but these errors were encountered: