Heterogenous Container
If you want to have a container that can store a fixed set of types, you can use one of boost::variant
:
typedef boost::variant<std::string, int> optval;
typedef std::vector<optval> options;
Now, you can push_back into the vector either strings or integers, and the variant will note what it contains:
options opts;
opts.push_back(10);
opts.push_back("hello");
You can read about it in its documentation at Boost variant, including how to get the right value out of the variant. You can of course also have a map from argument names to such variants, if you have already set up your command line parsing, and don't need libraries for that anymore:
std::map<std::string, optval> map;
map["--max-foo"] = 10;
map["--title"] = "something fun";
Command line parsing
If you want to parse the command line arguments of your program, you can look into the Boost.Program Options library, which will greatly assist you doing that.
Mostly, however, i end up using the posix getopt
function, which can also parse the command line. I recommend you to look into boost program options first, and if you feel it's too heavy, you can look into getopt (see man 3 getopt
)