Skip to content

Commit 680e2a7

Browse files
authored
[commands] Fix C++ Select() factory (#5024)
Update example to use it.
1 parent 9d83b06 commit 680e2a7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

include/frc2/command/Commands.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
#include <functional>
88
#include <initializer_list>
9+
#include <memory>
910
#include <span>
1011
#include <string>
12+
#include <type_traits>
1113
#include <utility>
1214
#include <vector>
1315

@@ -156,13 +158,15 @@ namespace cmd {
156158
* @param selector the selector function
157159
* @param commands map of commands to select from
158160
*/
159-
template <typename Key>
160-
[[nodiscard]] CommandPtr Select(
161-
std::function<Key()> selector,
162-
std::vector<std::pair<Key, CommandPtr>> commands) {
163-
return SelectCommand(std::move(selector),
164-
CommandPtr::UnwrapVector(std::move(commands)))
165-
.ToPtr();
161+
template <typename Key, class... Types>
162+
[[nodiscard]] CommandPtr Select(std::function<Key()> selector,
163+
std::pair<Key, Types>&&... commands) {
164+
std::vector<std::pair<Key, std::unique_ptr<Command>>> vec;
165+
166+
((void)vec.emplace_back(commands.first, std::move(commands.second).Unwrap()),
167+
...);
168+
169+
return SelectCommand(std::move(selector), std::move(vec)).ToPtr();
166170
}
167171

168172
// Command Groups

0 commit comments

Comments
 (0)