aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor C. Richberger <Taywee@gmx.com>2016-06-02 17:08:56 -0600
committerTaylor C. Richberger <Taywee@gmx.com>2016-06-02 17:08:56 -0600
commit13e4f40ec3e1535f46c2f3293981042af1e2776f (patch)
treeb6b39df7f8d9926049b3c0fb90ba2541f035ca13
parentimprove readability by culling explicit matcher construction (diff)
downloadargs.hxx-13e4f40ec3e1535f46c2f3293981042af1e2776f.tar.xz
allow set use4.1.5
-rw-r--r--Doxyfile2
-rw-r--r--args.hxx10
-rw-r--r--test.cxx19
3 files changed, 26 insertions, 5 deletions
diff --git a/Doxyfile b/Doxyfile
index 11391a7..51becfa 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME = "args"
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER = 4.1.4
+PROJECT_NUMBER = 4.1.5
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
diff --git a/args.hxx b/args.hxx
index e0d6f54..dcfa235 100644
--- a/args.hxx
+++ b/args.hxx
@@ -1435,8 +1435,9 @@ namespace args
virtual void ParseValue(const std::string &value) override
{
- values.emplace_back();
- Reader(name, value, values.back());
+ T v;
+ Reader(name, value, v);
+ values.insert(std::end(values), v);
}
/** Get the values
@@ -1610,8 +1611,9 @@ namespace args
virtual void ParseValue(const std::string &value) override
{
- values.emplace_back();
- Reader(name, value, values.back());
+ T v;
+ Reader(name, value, v);
+ values.insert(std::end(values), v);
matched = true;
}
diff --git a/test.cxx b/test.cxx
index 7822821..b4c451b 100644
--- a/test.cxx
+++ b/test.cxx
@@ -137,6 +137,16 @@ TEST_CASE("Argument flag lists work as expected", "[args]")
REQUIRE((args::get(foo) == std::vector<int>{7, 2, 9, 42}));
}
+#include <unordered_set>
+
+TEST_CASE("Argument flag lists work with sets", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::ValueFlagList<std::string, std::unordered_set<std::string>> foo(parser, "FOO", "test flag", {'f', "foo"});
+ parser.ParseArgs(std::vector<std::string>{"--foo=7", "-fblah", "-f", "9", "--foo", "blah"});
+ REQUIRE((args::get(foo) == std::unordered_set<std::string>{"7", "9", "blah"}));
+}
+
TEST_CASE("Positional arguments and positional argument lists work as expected", "[args]")
{
args::ArgumentParser parser("This is a test program.", "This goes after the options.");
@@ -152,6 +162,15 @@ TEST_CASE("Positional arguments and positional argument lists work as expected",
REQUIRE((args::get(baz) == std::vector<char>{'a', 'b', 'c', 'x', 'y', 'z'}));
}
+TEST_CASE("Positional lists work with sets", "[args]")
+{
+ args::ArgumentParser parser("This is a test program.", "This goes after the options.");
+ args::PositionalList<std::string, std::unordered_set<std::string>> foo(parser, "FOO", "test positional");
+ parser.ParseArgs(std::vector<std::string>{"foo", "FoO", "bar", "baz", "foo", "9", "baz"});
+ REQUIRE((args::get(foo) == std::unordered_set<std::string>{"foo", "FoO", "bar", "baz", "9"}));
+}
+
+
TEST_CASE("Positionals that are unspecified evaluate false", "[args]")
{
args::ArgumentParser parser("This is a test program.", "This goes after the options.");