[commands] C++ unique_ptr migration (#4319)

Add a CommandPtr with an internal unique_ptr to enable not needing to move the underlying classes, which is error-prone due to the potential for lambda captures.
This commit is contained in:
Starlight220
2022-10-06 01:19:28 +03:00
committed by GitHub
parent 3b81cf6c35
commit 60e29627c0
18 changed files with 644 additions and 133 deletions

View File

@@ -9,6 +9,7 @@
#include <utility>
#include "frc2/command/Command.h"
#include "frc2/command/CommandPtr.h"
namespace frc2 {
@@ -28,6 +29,11 @@ class CommandHelper : public Base {
public:
CommandHelper() = default;
CommandPtr ToPtr() && {
return CommandPtr(
std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this))));
}
protected:
std::unique_ptr<Command> TransferOwnership() && override {
return std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this)));