WPILibC++ 2023.4.3
InstantCommand.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 <functional>
8#include <initializer_list>
9#include <span>
10
13
14namespace frc2 {
15/**
16 * A Command that runs instantly; it will initialize, execute once, and end on
17 * the same iteration of the scheduler. Users can either pass in a Runnable and
18 * a set of requirements, or else subclass this command if desired.
19 *
20 * This class is provided by the NewCommands VendorDep
21 */
22class InstantCommand : public CommandHelper<FunctionalCommand, InstantCommand> {
23 public:
24 /**
25 * Creates a new InstantCommand that runs the given Runnable with the given
26 * requirements.
27 *
28 * @param toRun the Runnable to run
29 * @param requirements the subsystems required by this command
30 */
31 InstantCommand(std::function<void()> toRun,
32 std::initializer_list<Subsystem*> requirements);
33
34 /**
35 * Creates a new InstantCommand that runs the given Runnable with the given
36 * requirements.
37 *
38 * @param toRun the Runnable to run
39 * @param requirements the subsystems required by this command
40 */
41 explicit InstantCommand(std::function<void()> toRun,
42 std::span<Subsystem* const> requirements = {});
43
44 InstantCommand(InstantCommand&& other) = default;
45
46 InstantCommand(const InstantCommand& other) = default;
47
48 /**
49 * Creates a new InstantCommand with a Runnable that does nothing. Useful
50 * only as a no-arg constructor to call implicitly from subclass constructors.
51 */
53};
54} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26
A Command that runs instantly; it will initialize, execute once, and end on the same iteration of the...
Definition: InstantCommand.h:22
InstantCommand(std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Creates a new InstantCommand that runs the given Runnable with the given requirements.
InstantCommand(InstantCommand &&other)=default
InstantCommand()
Creates a new InstantCommand with a Runnable that does nothing.
InstantCommand(std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Creates a new InstantCommand that runs the given Runnable with the given requirements.
InstantCommand(const InstantCommand &other)=default
Definition: InstantCommand.h:14