Commit a687eb95871f863e5d22feb48345117838bac118
Committed by
Henry Schreiner
1 parent
343a730a
Add non-const version of App::get_options (#329)
Showing
1 changed file
with
16 additions
and
0 deletions
include/CLI/App.hpp
| ... | ... | @@ -1649,6 +1649,22 @@ class App { |
| 1649 | 1649 | return options; |
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | + /// Non-const version of the above | |
| 1653 | + std::vector<Option *> get_options(const std::function<bool(Option *)> filter = {}) { | |
| 1654 | + std::vector<Option *> options(options_.size()); | |
| 1655 | + std::transform(std::begin(options_), std::end(options_), std::begin(options), [](const Option_p &val) { | |
| 1656 | + return val.get(); | |
| 1657 | + }); | |
| 1658 | + | |
| 1659 | + if(filter) { | |
| 1660 | + options.erase( | |
| 1661 | + std::remove_if(std::begin(options), std::end(options), [&filter](Option *opt) { return !filter(opt); }), | |
| 1662 | + std::end(options)); | |
| 1663 | + } | |
| 1664 | + | |
| 1665 | + return options; | |
| 1666 | + } | |
| 1667 | + | |
| 1652 | 1668 | /// Get an option by name (noexcept non-const version) |
| 1653 | 1669 | Option *get_option_no_throw(std::string option_name) noexcept { |
| 1654 | 1670 | for(Option_p &opt : options_) { | ... | ... |