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 | 2 | |
| 3 | 3 | #include <string> |
| 4 | 4 | #include <regex> |
| 5 | +#include <deque> | |
| 5 | 6 | #include <iostream> |
| 6 | 7 | #include <functional> |
| 7 | 8 | #include <tuple> |
| ... | ... | @@ -321,7 +322,7 @@ protected: |
| 321 | 322 | std::string prog_discription; |
| 322 | 323 | std::vector<Option> options; |
| 323 | 324 | std::vector<std::string> missing_options; |
| 324 | - std::vector<std::string> positionals; | |
| 325 | + std::deque<std::string> positionals; | |
| 325 | 326 | std::vector<App*> subcommands; |
| 326 | 327 | bool parsed{false}; |
| 327 | 328 | App* subcommand = nullptr; |
| ... | ... | @@ -541,14 +542,12 @@ public: |
| 541 | 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 | 546 | for(Option& opt : options) { |
| 548 | 547 | while (opt.positional() && opt.count() < opt.expected() && positionals.size() > 0) { |
| 549 | 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 | 552 | if (opt.required() && opt.count() < opt.expected()) |
| 554 | 553 | throw RequiredError(opt.get_name()); | ... | ... |