cmdopt2/args: add vector bind

This commit is contained in:
Danny Robson 2022-03-21 10:47:48 +10:00
parent 86eafa366d
commit 153844eded

View File

@ -66,6 +66,26 @@ namespace cruft::cmdopt2 {
return get ();
}
template <typename ValueT>
BaseT
bind (std::vector<ValueT> &ref)
{
if (!repeat_)
throw std::logic_error ("vector argument with non-repeatable argument");
if constexpr (parseable<ValueT>) {
acceptor1 = [&ref] (char const* str) {
ref.emplace_back (parse::from_string<ValueT> (str));
};
} else {
acceptor1 = [&ref] (char const* str) {
ref.emplace_back (str);
};
}
return get ();
}
BaseT
get (void) const
{