[commands] Fix C++ Select() factory (#5024)

Update example to use it.
This commit is contained in:
Starlight220
2023-01-29 17:23:12 +02:00
committed by GitHub
parent f75acd11ce
commit 4054893669
3 changed files with 17 additions and 14 deletions

View File

@@ -6,8 +6,10 @@
#include <functional>
#include <initializer_list>
#include <memory>
#include <span>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
@@ -156,13 +158,15 @@ namespace cmd {
* @param selector the selector function
* @param commands map of commands to select from
*/
template <typename Key>
[[nodiscard]] CommandPtr Select(
std::function<Key()> selector,
std::vector<std::pair<Key, CommandPtr>> commands) {
return SelectCommand(std::move(selector),
CommandPtr::UnwrapVector(std::move(commands)))
.ToPtr();
template <typename Key, class... Types>
[[nodiscard]] CommandPtr Select(std::function<Key()> selector,
std::pair<Key, Types>&&... commands) {
std::vector<std::pair<Key, std::unique_ptr<Command>>> vec;
((void)vec.emplace_back(commands.first, std::move(commands.second).Unwrap()),
...);
return SelectCommand(std::move(selector), std::move(vec)).ToPtr();
}
// Command Groups