From 29baee5b10aacc4e554f1c8c54d216406b11f69b Mon Sep 17 00:00:00 2001 From: "Taylor C. Richberger" Date: Sun, 8 May 2016 21:50:41 -0600 Subject: some small const improvements --- args.hxx | 10 +++------- test.cxx | 3 +-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/args.hxx b/args.hxx index c03f381..817af7c 100644 --- a/args.hxx +++ b/args.hxx @@ -1007,7 +1007,7 @@ namespace args // Check short args } else if (!terminated && chunk.find(shortprefix) == 0 && chunk.size() > shortprefix.size()) { - std::string argchunk(chunk.substr(shortprefix.size())); + const std::string argchunk(chunk.substr(shortprefix.size())); for (auto argit = std::begin(argchunk); argit != std::end(argchunk); ++argit) { const char arg = *argit; @@ -1087,16 +1087,12 @@ namespace args { prog.assign(argv[0]); } - std::vector args; - for (int i = 1; i < argc; ++i) - { - args.emplace_back(argv[i]); - } + const std::vector args(argv + 1, argv + argc); ParseArgs(args); } }; - std::ostream &operator<<(std::ostream &os, ArgumentParser &parser) + std::ostream &operator<<(std::ostream &os, const ArgumentParser &parser) { parser.Help(os); return os; diff --git a/test.cxx b/test.cxx index f94f928..916bf9f 100644 --- a/test.cxx +++ b/test.cxx @@ -2,6 +2,7 @@ * This code is released under the license described in the LICENSE file */ +#include #include std::istream& operator>>(std::istream& is, std::tuple& ints) @@ -198,8 +199,6 @@ TEST_CASE("Argument groups should nest", "[args]") REQUIRE_THROWS_AS(parser.ParseArgs(std::vector{"-a", "-dg"}), args::ValidationError); } -#include - void DoublesReader(const std::string &name, const std::string &value, std::tuple &destination) { size_t commapos = 0; -- cgit v1.2.1