WPILibC++ 2024.3.2
CommandHelper.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <concepts>
8#include <memory>
9#include <utility>
10
11#include <wpi/deprecated.h>
12
15
16namespace frc2 {
17
18/**
19 * CRTP implementation to allow polymorphic decorator functions in Command.
20 *
21 * <p>Note: ALWAYS create a subclass by extending CommandHelper<Base, Subclass>,
22 * or decorators will not function!
23 *
24 * This class is provided by the NewCommands VendorDep
25 */
26template <std::derived_from<Command> Base, typename CRTP>
27class CommandHelper : public Base {
28 using Base::Base;
29
30 public:
31 CommandHelper() = default;
32
33 CommandPtr ToPtr() && override {
34 return CommandPtr(
35 std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this))));
36 }
37
38 protected:
39 WPI_DEPRECATED("Use ToPtr() instead")
40 std::unique_ptr<Command> TransferOwnership() && override {
41 return std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this)));
42 }
43};
44} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:27
std::unique_ptr< Command > TransferOwnership() &&override
Definition: CommandHelper.h:40
CommandHelper()=default
CommandPtr ToPtr() &&override
Definition: CommandHelper.h:33
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:41
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition: CommandPtr.h:29
Definition: TrapezoidProfileSubsystem.h:12
Definition: array.h:89