diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index fabbd764e0..7d5ddd0406 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -167,35 +167,96 @@ template // Command Groups +namespace impl { + +/** + * Create a vector of commands. + */ +template +std::vector MakeVector(Args&&... args) { + std::vector data; + data.reserve(sizeof...(Args)); + (data.emplace_back(std::forward(args)), ...); + return data; +} + +} // namespace impl + /** * Runs a group of commands in series, one after the other. */ [[nodiscard]] CommandPtr Sequence(std::vector&& commands); +/** + * Runs a group of commands in series, one after the other. + */ +template +[[nodiscard]] CommandPtr Sequence(Args&&... commands) { + return Sequence(impl::MakeVector(std::forward(commands)...)); +} + /** * Runs a group of commands in series, one after the other. Once the last * command ends, the group is restarted. */ [[nodiscard]] CommandPtr RepeatingSequence(std::vector&& commands); +/** + * Runs a group of commands in series, one after the other. Once the last + * command ends, the group is restarted. + */ +template +[[nodiscard]] CommandPtr RepeatingSequence(Args&&... commands) { + return RepeatingSequence(impl::MakeVector(std::forward(commands)...)); +} + /** * Runs a group of commands at the same time. Ends once all commands in the * group finish. */ [[nodiscard]] CommandPtr Parallel(std::vector&& commands); +/** + * Runs a group of commands at the same time. Ends once all commands in the + * group finish. + */ +template +[[nodiscard]] CommandPtr Parallel(Args&&... commands) { + return Parallel(impl::MakeVector(std::forward(commands)...)); +} + /** * Runs a group of commands at the same time. Ends once any command in the group * finishes, and cancels the others. */ [[nodiscard]] CommandPtr Race(std::vector&& commands); +/** + * Runs a group of commands at the same time. Ends once any command in the group + * finishes, and cancels the others. + */ +template +[[nodiscard]] CommandPtr Race(Args&&... commands) { + return Race(impl::MakeVector(std::forward(commands)...)); +} + /** * Runs a group of commands at the same time. Ends once a specific command * finishes, and cancels the others. */ [[nodiscard]] CommandPtr Deadline(CommandPtr&& deadline, std::vector&& others); + +/** + * Runs a group of commands at the same time. Ends once a specific command + * finishes, and cancels the others. + */ +template +[[nodiscard]] CommandPtr Deadline(CommandPtr&& deadline, Args&&... commands) { + return Deadline(std::move(deadline), + impl::MakeVector(std::forward(commands)...)); +} + } // namespace cmd } // namespace frc2