From 17ddce2fb2e76d538ec449c395ae9ae0a36ca215 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Tue, 30 Jul 2019 06:46:10 -0700 Subject: [PATCH] Add classification type traits (#286) This cleans up the type checking a bit and makes it more readable, along with some other cleanup. * start work on trying to clean up the type traits for which lexical cast overload to use * fix readme issue and make the condition tests a little clearer * add a check for out of range errors on boolean conversions * Fix capitalization and some comments on option functions * fix a few code analysis warnings for VS2019 --- README.md | 2 +- include/CLI/App.hpp | 4 +- include/CLI/Option.hpp | 14 +-- include/CLI/TypeTools.hpp | 215 ++++++++++++++++++++++++++------------ tests/AppTest.cpp | 9 ++ tests/OptionGroupTest.cpp | 2 +- 6 files changed, 171 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 2a96e559..22d15069 100644 --- a/README.md +++ b/README.md @@ -604,7 +604,7 @@ The subcommand method .add_option_group(name,description) ``` -Will create an option group, and return a pointer to it. An option group allows creation of a collection of options, similar to the groups function on options, but with additional controls and requirements. They allow specific sets of options to be composed and controlled as a collective. For an example see [range test](./tests/ranges.cpp). Option groups are a specialization of an App so all [functions](#subcommand-options) that work with an App or subcommand also work on option groups. Options can be created as part of an option group using the add functions just like a subcommand, or previously created options can be added through +Will create an option group, and return a pointer to it. An option group allows creation of a collection of options, similar to the groups function on options, but with additional controls and requirements. They allow specific sets of options to be composed and controlled as a collective. For an example see [range example](https://github.com/CLIUtils/CLI11/blob/master/examples/ranges.cpp). Option groups are a specialization of an App so all [functions](#subcommand-options) that work with an App or subcommand also work on option groups. Options can be created as part of an option group using the add functions just like a subcommand, or previously created options can be added through ```cpp ogroup->add_option(option_pointer); diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index c1e06b34..1e19607b 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -1292,7 +1292,7 @@ class App { } std::vector args; - args.reserve(static_cast(argc - 1)); + args.reserve(static_cast(argc) - 1); for(int i = argc - 1; i > 0; i--) args.emplace_back(argv[i]); parse(std::move(args)); @@ -2317,7 +2317,7 @@ class App { // LCOV_EXCL_START default: - HorribleError("unrecognized classifier (you should not see this!)"); + throw HorribleError("unrecognized classifier (you should not see this!)"); // LCOV_EXCL_END } return retval; diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index 3d90ab87..024e2fb7 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -527,7 +527,7 @@ class Option : public OptionBase