return result;
}
+void
+Args::erase_last(string_view arg)
+{
+ const auto it = std::find(m_args.rbegin(), m_args.rend(), arg);
+ if (it != m_args.rend()) {
+ m_args.erase(std::next(it).base());
+ }
+}
+
void
Args::erase_with_prefix(string_view prefix)
{
// in arguments is performed.
std::string to_string() const;
+ // Remove last argument equal to `arg`, if any.
+ void erase_last(nonstd::string_view arg);
+
// Remove all arguments with prefix `prefix`.
void erase_with_prefix(nonstd::string_view prefix);
Args more_args = Args::from_string("x y");
Args no_args;
+ SUBCASE("erase_last")
+ {
+ Args repeated_args = Args::from_string("one two twotwo one two twotwo");
+
+ repeated_args.erase_last("three");
+ CHECK(repeated_args == Args::from_string("one two twotwo one two twotwo"));
+
+ repeated_args.erase_last("two");
+ CHECK(repeated_args == Args::from_string("one two twotwo one twotwo"));
+
+ repeated_args.erase_last("two");
+ CHECK(repeated_args == Args::from_string("one twotwo one twotwo"));
+
+ repeated_args.erase_last("two");
+ CHECK(repeated_args == Args::from_string("one twotwo one twotwo"));
+ }
+
SUBCASE("erase_with_prefix")
{
args.erase_with_prefix("m");