0

So, what I am searching for would maybe look like this (without the xxx):

const xxx<std::string, std::string, void (*)(std::string)> commands = {
  {"exit", "Exit Program", f1},
  {"test", "Start Test", f2},
  {"help, h", "Help Screen", f3}
};

As far as I know, lists, vectors, maps, etc. can't do that. Is there anything I can just replace the xxx with? Or is there an easy other way to do it?

Leon
  • 35
  • 5

1 Answers1

2

At a basic level, you can use std::tuple: std::tuple<std::string, std::string, std::function<void(std::string)> command which can hold any number of types.

If you want more than one, use a std::vector<std::tuple<...>>:

using Command = std::tuple<std::string, std::string, std::function<void(std::string)>>;
using CommandList = std::vector<Command>;

CommandList commands;

For more advanced compositions, a custom user-defined type is easier, but for only three types it's not really worth it.

Casey
  • 10,297
  • 11
  • 59
  • 88