WPILibC++  2020.3.2-60-g3011ebe
CommandHelper.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 #include <type_traits>
12 #include <utility>
13 
14 #include "frc2/command/Command.h"
15 
16 namespace frc2 {
17 
24 template <typename Base, typename CRTP,
25  typename = std::enable_if_t<std::is_base_of_v<Command, Base>>>
26 class CommandHelper : public Base {
27  using Base::Base;
28 
29  public:
30  CommandHelper() = default;
31 
32  protected:
33  std::unique_ptr<Command> TransferOwnership() && override {
34  return std::make_unique<CRTP>(std::move(*static_cast<CRTP*>(this)));
35  }
36 };
37 } // namespace frc2
frc2::CommandHelper
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26