add vectors

This commit is contained in:
Jarryd Beck 2014-10-09 14:09:02 +11:00
parent 2fd9ab63fc
commit d7271eda80
2 changed files with 16 additions and 3 deletions

View File

@ -51,6 +51,15 @@ namespace cxxopts
is >> value; is >> value;
} }
template <typename T>
void
parse_value(const std::string& text, std::vector<T>& value)
{
T v;
parse_value(text, v);
value.push_back(v);
}
template <typename T> template <typename T>
struct value_has_arg struct value_has_arg
{ {

View File

@ -36,7 +36,7 @@ int main(int argc, char* argv[])
options.add_options() options.add_options()
("a,apple", "an apple") ("a,apple", "an apple")
("b,bob", "Bob") ("b,bob", "Bob")
("f,file", "File", cxxopts::value<std::string>()) ("f,file", "File", cxxopts::value<std::vector<std::string>>())
("positional", "Positional arguments", cxxopts::value<std::string>()) ("positional", "Positional arguments", cxxopts::value<std::string>())
; ;
@ -56,8 +56,12 @@ int main(int argc, char* argv[])
if (options.count("f")) if (options.count("f"))
{ {
std::cout << "File = " << options["f"].as<std::string>() auto& ff = options["f"].as<std::vector<std::string>>();
<< std::endl; std::cout << "Files" << std::endl;
for (const auto& f : ff)
{
std::cout << f << std::endl;
}
} }
if (options.count("help")) if (options.count("help"))