diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index 8b38275eba..ccf738b29d 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -6,8 +6,10 @@ #include #include +#include #include #include +#include #include #include @@ -156,13 +158,15 @@ namespace cmd { * @param selector the selector function * @param commands map of commands to select from */ -template -[[nodiscard]] CommandPtr Select( - std::function selector, - std::vector> commands) { - return SelectCommand(std::move(selector), - CommandPtr::UnwrapVector(std::move(commands))) - .ToPtr(); +template +[[nodiscard]] CommandPtr Select(std::function selector, + std::pair&&... commands) { + std::vector>> vec; + + ((void)vec.emplace_back(commands.first, std::move(commands.second).Unwrap()), + ...); + + return SelectCommand(std::move(selector), std::move(vec)).ToPtr(); } // Command Groups diff --git a/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp index 573fcacc51..69895cb1ca 100644 --- a/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SelectCommand/cpp/RobotContainer.cpp @@ -17,5 +17,5 @@ void RobotContainer::ConfigureButtonBindings() { frc2::Command* RobotContainer::GetAutonomousCommand() { // Run the select command in autonomous - return &m_exampleSelectCommand; + return m_exampleSelectCommand.get(); } diff --git a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h index 40eea3347a..a1a2c86fac 100644 --- a/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h +++ b/wpilibcExamples/src/main/cpp/examples/SelectCommand/include/RobotContainer.h @@ -5,8 +5,7 @@ #pragma once #include -#include -#include +#include /** * This class is where the bulk of the robot should be declared. Since @@ -36,12 +35,12 @@ class RobotContainer { // value returned by the selector method at runtime. Note that selectcommand // takes a generic type, so the selector does not have to be an enum; it could // be any desired type (string, integer, boolean, double...) - frc2::SelectCommand m_exampleSelectCommand{ + frc2::CommandPtr m_exampleSelectCommand = frc2::cmd::Select( [this] { return Select(); }, // Maps selector values to commands - std::pair{ONE, frc2::PrintCommand{"Command one was selected!"}}, - std::pair{TWO, frc2::PrintCommand{"Command two was selected!"}}, - std::pair{THREE, frc2::PrintCommand{"Command three was selected!"}}}; + std::pair{ONE, frc2::cmd::Print("Command one was selected!")}, + std::pair{TWO, frc2::cmd::Print("Command two was selected!")}, + std::pair{THREE, frc2::cmd::Print("Command three was selected!")}); void ConfigureButtonBindings(); };