Commit b5ea5ce065859008697d543f118dd2df6af3e1f5
1 parent
30a91b4a
Change positionals to deque, no reverse needed
Showing
1 changed file
with
4 additions
and
5 deletions
include/CLI.hpp
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | #include <string> | 3 | #include <string> |
| 4 | #include <regex> | 4 | #include <regex> |
| 5 | +#include <deque> | ||
| 5 | #include <iostream> | 6 | #include <iostream> |
| 6 | #include <functional> | 7 | #include <functional> |
| 7 | #include <tuple> | 8 | #include <tuple> |
| @@ -321,7 +322,7 @@ protected: | @@ -321,7 +322,7 @@ protected: | ||
| 321 | std::string prog_discription; | 322 | std::string prog_discription; |
| 322 | std::vector<Option> options; | 323 | std::vector<Option> options; |
| 323 | std::vector<std::string> missing_options; | 324 | std::vector<std::string> missing_options; |
| 324 | - std::vector<std::string> positionals; | 325 | + std::deque<std::string> positionals; |
| 325 | std::vector<App*> subcommands; | 326 | std::vector<App*> subcommands; |
| 326 | bool parsed{false}; | 327 | bool parsed{false}; |
| 327 | App* subcommand = nullptr; | 328 | App* subcommand = nullptr; |
| @@ -541,14 +542,12 @@ public: | @@ -541,14 +542,12 @@ public: | ||
| 541 | throw CallForHelp(); | 542 | throw CallForHelp(); |
| 542 | } | 543 | } |
| 543 | 544 | ||
| 544 | - // Positionals end up being inserted in the correct order, but we want to pop them off the back end | ||
| 545 | - std::reverse(std::begin(positionals), std::end(positionals)); | ||
| 546 | 545 | ||
| 547 | for(Option& opt : options) { | 546 | for(Option& opt : options) { |
| 548 | while (opt.positional() && opt.count() < opt.expected() && positionals.size() > 0) { | 547 | while (opt.positional() && opt.count() < opt.expected() && positionals.size() > 0) { |
| 549 | opt.get_new(); | 548 | opt.get_new(); |
| 550 | - opt.add_result(0, positionals.back()); | ||
| 551 | - positionals.pop_back(); | 549 | + opt.add_result(0, positionals.front()); |
| 550 | + positionals.pop_front(); | ||
| 552 | } | 551 | } |
| 553 | if (opt.required() && opt.count() < opt.expected()) | 552 | if (opt.required() && opt.count() < opt.expected()) |
| 554 | throw RequiredError(opt.get_name()); | 553 | throw RequiredError(opt.get_name()); |