mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Rename size_t -> std::size_t
This commit is contained in:
parent
ed7e0dcdeb
commit
d5cd986046
@ -568,7 +568,7 @@ There are several options that are supported on the main app and subcommands and
|
||||
- `.parse_complete_callback(void() function)`: 🚧 Set the callback that runs at the completion of parsing. for subcommands this is executed at the completion of the single subcommand and can be executed multiple times. See [Subcommand callbacks](#callbacks) for some additional details.
|
||||
- `.final_callback(void() function)`: 🚧 Set the callback that runs at the end of all processing. This is the last thing that is executed before returning. See [Subcommand callbacks](#callbacks) for some additional details.
|
||||
- `.immediate_callback()`: 🆕 Specifies whether the callback for a subcommand should be run as a `parse_complete_callback`(true) or `final_callback`(false). When used on the main app 🚧 it will execute the main app callback prior to the callbacks for a subcommand if they do not also have the `immediate_callback` flag set. 🚧 It is preferable to use the `parse_complete_callback` or `final_callback` directly instead of the `callback` and `immediate_callback` if one wishes to control the ordering and timing of callback. Though `immediate_callback` can be used to swap them if that is needed.
|
||||
- `.pre_parse_callback(void(size_t) function)`: 🆕 Set a callback that executes after the first argument of an application is processed. See [Subcommand callbacks](#callbacks) for some additional details.
|
||||
- `.pre_parse_callback(void(std::size_t) function)`: 🆕 Set a callback that executes after the first argument of an application is processed. See [Subcommand callbacks](#callbacks) for some additional details.
|
||||
- `.allow_extras()`: Do not throw an error if extra arguments are left over.
|
||||
- `.positionals_at_end()`: 🆕 Specify that positional arguments occur as the last arguments and throw an error if an unexpected positional is encountered.
|
||||
- `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognized item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app.
|
||||
|
@ -37,7 +37,7 @@ After parsing, you can use `my_flag->count()` to count the number of times this
|
||||
|
||||
## Callback flags
|
||||
|
||||
If you want to define a callback that runs when you make a flag, you can use `add_flag_function` (C++11 or newer) or `add_flag` (C++14 or newer only) to add a callback function. The function should have the signature `void(size_t)`. This could be useful for a version printout, etc.
|
||||
If you want to define a callback that runs when you make a flag, you can use `add_flag_function` (C++11 or newer) or `add_flag` (C++14 or newer only) to add a callback function. The function should have the signature `void(std::size_t)`. This could be useful for a version printout, etc.
|
||||
|
||||
```
|
||||
auto callback = [](int count){std::cout << "This was called " << count << " times";};
|
||||
|
@ -13,7 +13,7 @@ int main(int argc, char **argv) {
|
||||
files->add_option("file1", file1, "first file")->required();
|
||||
files->add_option("file2", file2, "second file");
|
||||
// set a pre parse callback that turns the numbers group on or off depending on the number of arguments
|
||||
app.preparse_callback([numbers](size_t arity) {
|
||||
app.preparse_callback([numbers](std::size_t arity) {
|
||||
if(arity <= 2) {
|
||||
numbers->disabled();
|
||||
} else {
|
||||
|
@ -96,7 +96,7 @@ class App {
|
||||
bool immediate_callback_{false};
|
||||
|
||||
/// This is a function that runs prior to the start of parsing
|
||||
std::function<void(size_t)> pre_parse_callback_{};
|
||||
std::function<void(std::size_t)> pre_parse_callback_{};
|
||||
|
||||
/// This is a function that runs when parsing has finished.
|
||||
std::function<void()> parse_complete_callback_{};
|
||||
@ -204,19 +204,19 @@ class App {
|
||||
App *parent_{nullptr};
|
||||
|
||||
/// Counts the number of times this command/subcommand was parsed
|
||||
size_t parsed_{0};
|
||||
std::size_t parsed_{0};
|
||||
|
||||
/// Minimum required subcommands (not inheritable!)
|
||||
size_t require_subcommand_min_{0};
|
||||
std::size_t require_subcommand_min_{0};
|
||||
|
||||
/// Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE
|
||||
size_t require_subcommand_max_{0};
|
||||
std::size_t require_subcommand_max_{0};
|
||||
|
||||
/// Minimum required options (not inheritable!)
|
||||
size_t require_option_min_{0};
|
||||
std::size_t require_option_min_{0};
|
||||
|
||||
/// Max number of options allowed. 0 is unlimited (not inheritable)
|
||||
size_t require_option_max_{0};
|
||||
std::size_t require_option_max_{0};
|
||||
|
||||
/// The group membership INHERITABLE
|
||||
std::string group_{"Subcommands"};
|
||||
@ -322,7 +322,7 @@ class App {
|
||||
|
||||
/// Set a callback to execute prior to parsing.
|
||||
///
|
||||
App *preparse_callback(std::function<void(size_t)> pp_callback) {
|
||||
App *preparse_callback(std::function<void(std::size_t)> pp_callback) {
|
||||
pre_parse_callback_ = std::move(pp_callback);
|
||||
return this;
|
||||
}
|
||||
@ -1056,12 +1056,12 @@ class App {
|
||||
/// No argument version of count counts the number of times this subcommand was
|
||||
/// passed in. The main app will return 1. Unnamed subcommands will also return 1 unless
|
||||
/// otherwise modified in a callback
|
||||
size_t count() const { return parsed_; }
|
||||
std::size_t count() const { return parsed_; }
|
||||
|
||||
/// Get a count of all the arguments processed in options and subcommands, this excludes arguments which were
|
||||
/// treated as extras.
|
||||
size_t count_all() const {
|
||||
size_t cnt{0};
|
||||
std::size_t count_all() const {
|
||||
std::size_t cnt{0};
|
||||
for(auto &opt : options_) {
|
||||
cnt += opt->count();
|
||||
}
|
||||
@ -1093,17 +1093,17 @@ class App {
|
||||
App *require_subcommand(int value) {
|
||||
if(value < 0) {
|
||||
require_subcommand_min_ = 0;
|
||||
require_subcommand_max_ = static_cast<size_t>(-value);
|
||||
require_subcommand_max_ = static_cast<std::size_t>(-value);
|
||||
} else {
|
||||
require_subcommand_min_ = static_cast<size_t>(value);
|
||||
require_subcommand_max_ = static_cast<size_t>(value);
|
||||
require_subcommand_min_ = static_cast<std::size_t>(value);
|
||||
require_subcommand_max_ = static_cast<std::size_t>(value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Explicitly control the number of subcommands required. Setting 0
|
||||
/// for the max means unlimited number allowed. Max number inheritable.
|
||||
App *require_subcommand(size_t min, size_t max) {
|
||||
App *require_subcommand(std::size_t min, std::size_t max) {
|
||||
require_subcommand_min_ = min;
|
||||
require_subcommand_max_ = max;
|
||||
return this;
|
||||
@ -1122,17 +1122,17 @@ class App {
|
||||
App *require_option(int value) {
|
||||
if(value < 0) {
|
||||
require_option_min_ = 0;
|
||||
require_option_max_ = static_cast<size_t>(-value);
|
||||
require_option_max_ = static_cast<std::size_t>(-value);
|
||||
} else {
|
||||
require_option_min_ = static_cast<size_t>(value);
|
||||
require_option_max_ = static_cast<size_t>(value);
|
||||
require_option_min_ = static_cast<std::size_t>(value);
|
||||
require_option_max_ = static_cast<std::size_t>(value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Explicitly control the number of options required. Setting 0
|
||||
/// for the max means unlimited number allowed. Max number inheritable.
|
||||
App *require_option(size_t min, size_t max) {
|
||||
App *require_option(std::size_t min, std::size_t max) {
|
||||
require_option_min_ = min;
|
||||
require_option_max_ = max;
|
||||
return this;
|
||||
@ -1188,7 +1188,7 @@ class App {
|
||||
}
|
||||
|
||||
std::vector<std::string> args;
|
||||
args.reserve(static_cast<size_t>(argc) - 1);
|
||||
args.reserve(static_cast<std::size_t>(argc) - 1);
|
||||
for(int i = argc - 1; i > 0; i--)
|
||||
args.emplace_back(argv[i]);
|
||||
parse(std::move(args));
|
||||
@ -1300,7 +1300,7 @@ class App {
|
||||
///@{
|
||||
|
||||
/// Counts the number of times the given option was passed.
|
||||
size_t count(std::string option_name) const { return get_option(option_name)->count(); }
|
||||
std::size_t count(std::string option_name) const { return get_option(option_name)->count(); }
|
||||
|
||||
/// Get a subcommand pointer list to the currently selected subcommands (after parsing by default, in command
|
||||
/// line order; use parsed = false to get the original definition list.)
|
||||
@ -1608,16 +1608,16 @@ class App {
|
||||
std::string get_footer() const { return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_; }
|
||||
|
||||
/// Get the required min subcommand value
|
||||
size_t get_require_subcommand_min() const { return require_subcommand_min_; }
|
||||
std::size_t get_require_subcommand_min() const { return require_subcommand_min_; }
|
||||
|
||||
/// Get the required max subcommand value
|
||||
size_t get_require_subcommand_max() const { return require_subcommand_max_; }
|
||||
std::size_t get_require_subcommand_max() const { return require_subcommand_max_; }
|
||||
|
||||
/// Get the required min option value
|
||||
size_t get_require_option_min() const { return require_option_min_; }
|
||||
std::size_t get_require_option_min() const { return require_option_min_; }
|
||||
|
||||
/// Get the required max option value
|
||||
size_t get_require_option_max() const { return require_option_max_; }
|
||||
std::size_t get_require_option_max() const { return require_option_max_; }
|
||||
|
||||
/// Get the prefix command status
|
||||
bool get_prefix_command() const { return prefix_command_; }
|
||||
@ -1762,8 +1762,8 @@ class App {
|
||||
}
|
||||
|
||||
/// This returns the number of remaining options, minus the -- separator
|
||||
size_t remaining_size(bool recurse = false) const {
|
||||
auto remaining_options = static_cast<size_t>(std::count_if(
|
||||
std::size_t remaining_size(bool recurse = false) const {
|
||||
auto remaining_options = static_cast<std::size_t>(std::count_if(
|
||||
std::begin(missing_), std::end(missing_), [](const std::pair<detail::Classifier, std::string> &val) {
|
||||
return val.first != detail::Classifier::POSITIONAL_MARK;
|
||||
}));
|
||||
@ -1798,7 +1798,7 @@ class App {
|
||||
}
|
||||
}
|
||||
|
||||
size_t nameless_subs{0};
|
||||
std::size_t nameless_subs{0};
|
||||
for(const App_p &app : subcommands_) {
|
||||
app->_validate();
|
||||
if(app->get_name().empty())
|
||||
@ -1943,7 +1943,7 @@ class App {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Windows version
|
||||
size_t sz = 0;
|
||||
std::size_t sz = 0;
|
||||
if(_dupenv_s(&buffer, &sz, opt->envname_.c_str()) == 0 && buffer != nullptr) {
|
||||
ename_string = std::string(buffer);
|
||||
free(buffer);
|
||||
@ -2065,7 +2065,7 @@ class App {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t used_options = 0;
|
||||
std::size_t used_options = 0;
|
||||
for(const Option_p &opt : options_) {
|
||||
|
||||
if(opt->count() != 0) {
|
||||
@ -2155,7 +2155,7 @@ class App {
|
||||
/// Throw an error if anything is left over and should not be.
|
||||
void _process_extras() {
|
||||
if(!(allow_extras_ || prefix_command_)) {
|
||||
size_t num_left_over = remaining_size();
|
||||
std::size_t num_left_over = remaining_size();
|
||||
if(num_left_over > 0) {
|
||||
throw ExtrasError(name_, remaining(false));
|
||||
}
|
||||
@ -2171,7 +2171,7 @@ class App {
|
||||
/// Modifies the args to fill in the missing items before throwing.
|
||||
void _process_extras(std::vector<std::string> &args) {
|
||||
if(!(allow_extras_ || prefix_command_)) {
|
||||
size_t num_left_over = remaining_size();
|
||||
std::size_t num_left_over = remaining_size();
|
||||
if(num_left_over > 0) {
|
||||
args = remaining(false);
|
||||
throw ExtrasError(name_, args);
|
||||
@ -2250,7 +2250,7 @@ class App {
|
||||
}
|
||||
|
||||
/// Fill in a single config option
|
||||
bool _parse_single_config(const ConfigItem &item, size_t level = 0) {
|
||||
bool _parse_single_config(const ConfigItem &item, std::size_t level = 0) {
|
||||
if(level < item.parents.size()) {
|
||||
try {
|
||||
auto subcom = get_subcommand(item.parents.at(level));
|
||||
@ -2334,13 +2334,13 @@ class App {
|
||||
}
|
||||
|
||||
/// Count the required remaining positional arguments
|
||||
size_t _count_remaining_positionals(bool required_only = false) const {
|
||||
size_t retval = 0;
|
||||
std::size_t _count_remaining_positionals(bool required_only = false) const {
|
||||
std::size_t retval = 0;
|
||||
for(const Option_p &opt : options_) {
|
||||
if(opt->get_positional() && (!required_only || opt->get_required())) {
|
||||
if(opt->get_items_expected_min() > 0 &&
|
||||
static_cast<int>(opt->count()) < opt->get_items_expected_min()) {
|
||||
retval += static_cast<size_t>(opt->get_items_expected_min()) - opt->count();
|
||||
retval += static_cast<std::size_t>(opt->get_items_expected_min()) - opt->count();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2655,7 +2655,7 @@ class App {
|
||||
}
|
||||
|
||||
/// Trigger the pre_parse callback if needed
|
||||
void _trigger_pre_parse(size_t remaining_args) {
|
||||
void _trigger_pre_parse(std::size_t remaining_args) {
|
||||
if(!pre_parse_called_) {
|
||||
pre_parse_called_ = true;
|
||||
if(pre_parse_callback_) {
|
||||
@ -2831,7 +2831,7 @@ class Option_group : public App {
|
||||
inline void TriggerOn(App *trigger_app, App *app_to_enable) {
|
||||
app_to_enable->enabled_by_default(false);
|
||||
app_to_enable->disabled_by_default();
|
||||
trigger_app->preparse_callback([app_to_enable](size_t) { app_to_enable->disabled(false); });
|
||||
trigger_app->preparse_callback([app_to_enable](std::size_t) { app_to_enable->disabled(false); });
|
||||
}
|
||||
|
||||
/// Helper function to enable one option group/subcommand when another is used
|
||||
@ -2841,7 +2841,7 @@ inline void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable) {
|
||||
app->disabled_by_default();
|
||||
}
|
||||
|
||||
trigger_app->preparse_callback([apps_to_enable](size_t) {
|
||||
trigger_app->preparse_callback([apps_to_enable](std::size_t) {
|
||||
for(auto &app : apps_to_enable) {
|
||||
app->disabled(false);
|
||||
}
|
||||
@ -2852,7 +2852,7 @@ inline void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable) {
|
||||
inline void TriggerOff(App *trigger_app, App *app_to_enable) {
|
||||
app_to_enable->disabled_by_default(false);
|
||||
app_to_enable->enabled_by_default();
|
||||
trigger_app->preparse_callback([app_to_enable](size_t) { app_to_enable->disabled(); });
|
||||
trigger_app->preparse_callback([app_to_enable](std::size_t) { app_to_enable->disabled(); });
|
||||
}
|
||||
|
||||
/// Helper function to disable one option group/subcommand when another is used
|
||||
@ -2862,7 +2862,7 @@ inline void TriggerOff(App *trigger_app, std::vector<App *> apps_to_enable) {
|
||||
app->enabled_by_default();
|
||||
}
|
||||
|
||||
trigger_app->preparse_callback([apps_to_enable](size_t) {
|
||||
trigger_app->preparse_callback([apps_to_enable](std::size_t) {
|
||||
for(auto &app : apps_to_enable) {
|
||||
app->disabled();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace detail {
|
||||
/// Comma separated join, adds quotes if needed
|
||||
inline std::string ini_join(std::vector<std::string> args) {
|
||||
std::ostringstream s;
|
||||
size_t start = 0;
|
||||
std::size_t start = 0;
|
||||
for(const auto &arg : args) {
|
||||
if(start++ > 0)
|
||||
s << " ";
|
||||
@ -107,7 +107,7 @@ class ConfigINI : public Config {
|
||||
std::vector<std::string> items_buffer;
|
||||
|
||||
detail::trim(line);
|
||||
size_t len = line.length();
|
||||
std::size_t len = line.length();
|
||||
if(len > 1 && line[0] == '[' && line[len - 1] == ']') {
|
||||
section = line.substr(1, len - 2);
|
||||
} else if(len > 0 && line[0] != ';') {
|
||||
|
@ -205,14 +205,15 @@ class ValidationError : public ParseError {
|
||||
class RequiredError : public ParseError {
|
||||
CLI11_ERROR_DEF(ParseError, RequiredError)
|
||||
explicit RequiredError(std::string name) : RequiredError(name + " is required", ExitCodes::RequiredError) {}
|
||||
static RequiredError Subcommand(size_t min_subcom) {
|
||||
static RequiredError Subcommand(std::size_t min_subcom) {
|
||||
if(min_subcom == 1) {
|
||||
return RequiredError("A subcommand");
|
||||
}
|
||||
return RequiredError("Requires at least " + std::to_string(min_subcom) + " subcommands",
|
||||
ExitCodes::RequiredError);
|
||||
}
|
||||
static RequiredError Option(size_t min_option, size_t max_option, size_t used, const std::string &option_list) {
|
||||
static RequiredError
|
||||
Option(std::size_t min_option, std::size_t max_option, std::size_t used, const std::string &option_list) {
|
||||
if((min_option == 1) && (max_option == 1) && (used == 0))
|
||||
return RequiredError("Exactly 1 option from [" + option_list + "]");
|
||||
if((min_option == 1) && (max_option == 1) && (used > 1))
|
||||
@ -239,18 +240,18 @@ class RequiredError : public ParseError {
|
||||
class ArgumentMismatch : public ParseError {
|
||||
CLI11_ERROR_DEF(ParseError, ArgumentMismatch)
|
||||
CLI11_ERROR_SIMPLE(ArgumentMismatch)
|
||||
ArgumentMismatch(std::string name, int expected, size_t recieved)
|
||||
ArgumentMismatch(std::string name, int expected, std::size_t recieved)
|
||||
: ArgumentMismatch(expected > 0 ? ("Expected exactly " + std::to_string(expected) + " arguments to " + name +
|
||||
", got " + std::to_string(recieved))
|
||||
: ("Expected at least " + std::to_string(-expected) + " arguments to " + name +
|
||||
", got " + std::to_string(recieved)),
|
||||
ExitCodes::ArgumentMismatch) {}
|
||||
|
||||
static ArgumentMismatch AtLeast(std::string name, int num, size_t received) {
|
||||
static ArgumentMismatch AtLeast(std::string name, int num, std::size_t received) {
|
||||
return ArgumentMismatch(name + ": At least " + std::to_string(num) + " required but received " +
|
||||
std::to_string(received));
|
||||
}
|
||||
static ArgumentMismatch AtMost(std::string name, int num, size_t received) {
|
||||
static ArgumentMismatch AtMost(std::string name, int num, std::size_t received) {
|
||||
return ArgumentMismatch(name + ": At Most " + std::to_string(num) + " required but received " +
|
||||
std::to_string(received));
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class FormatterBase {
|
||||
///@{
|
||||
|
||||
/// The width of the first column
|
||||
size_t column_width_{30};
|
||||
std::size_t column_width_{30};
|
||||
|
||||
/// @brief The required help printout labels (user changeable)
|
||||
/// Values are Needs, Excludes, etc.
|
||||
@ -64,7 +64,7 @@ class FormatterBase {
|
||||
void label(std::string key, std::string val) { labels_[key] = val; }
|
||||
|
||||
/// Set the column width
|
||||
void column_width(size_t val) { column_width_ = val; }
|
||||
void column_width(std::size_t val) { column_width_ = val; }
|
||||
|
||||
///@}
|
||||
/// @name Getters
|
||||
@ -79,7 +79,7 @@ class FormatterBase {
|
||||
}
|
||||
|
||||
/// Get the current column width
|
||||
size_t get_column_width() const { return column_width_; }
|
||||
std::size_t get_column_width() const { return column_width_; }
|
||||
|
||||
///@}
|
||||
};
|
||||
|
@ -340,7 +340,7 @@ class Option : public OptionBase<Option> {
|
||||
Option &operator=(const Option &) = delete;
|
||||
|
||||
/// Count the total number of times an option was passed
|
||||
size_t count() const { return results_.size(); }
|
||||
std::size_t count() const { return results_.size(); }
|
||||
|
||||
/// True if the option was not passed
|
||||
bool empty() const { return results_.empty(); }
|
||||
@ -870,8 +870,8 @@ class Option : public OptionBase<Option> {
|
||||
if(!((input_value.empty()) || (input_value == emptyString))) {
|
||||
auto default_ind = detail::find_member(name, fnames_, ignore_case_, ignore_underscore_);
|
||||
if(default_ind >= 0) {
|
||||
// We can static cast this to size_t because it is more than 0 in this block
|
||||
if(default_flag_values_[static_cast<size_t>(default_ind)].second != input_value) {
|
||||
// We can static cast this to std::size_t because it is more than 0 in this block
|
||||
if(default_flag_values_[static_cast<std::size_t>(default_ind)].second != input_value) {
|
||||
throw(ArgumentMismatch::FlagOverride(name));
|
||||
}
|
||||
} else {
|
||||
@ -884,15 +884,15 @@ class Option : public OptionBase<Option> {
|
||||
auto ind = detail::find_member(name, fnames_, ignore_case_, ignore_underscore_);
|
||||
if((input_value.empty()) || (input_value == emptyString)) {
|
||||
if(flag_like_) {
|
||||
return (ind < 0) ? trueString : default_flag_values_[static_cast<size_t>(ind)].second;
|
||||
return (ind < 0) ? trueString : default_flag_values_[static_cast<std::size_t>(ind)].second;
|
||||
} else {
|
||||
return (ind < 0) ? default_str_ : default_flag_values_[static_cast<size_t>(ind)].second;
|
||||
return (ind < 0) ? default_str_ : default_flag_values_[static_cast<std::size_t>(ind)].second;
|
||||
}
|
||||
}
|
||||
if(ind < 0) {
|
||||
return input_value;
|
||||
}
|
||||
if(default_flag_values_[static_cast<size_t>(ind)].second == falseString) {
|
||||
if(default_flag_values_[static_cast<std::size_t>(ind)].second == falseString) {
|
||||
try {
|
||||
auto val = detail::to_flag_value(input_value);
|
||||
return (val == 1) ? falseString : (val == (-1) ? trueString : std::to_string(-val));
|
||||
@ -1145,15 +1145,15 @@ class Option : public OptionBase<Option> {
|
||||
break;
|
||||
case MultiOptionPolicy::TakeLast: {
|
||||
// Allow multi-option sizes (including 0)
|
||||
size_t trim_size =
|
||||
std::min<size_t>(static_cast<size_t>(std::max<int>(get_items_expected_max(), 1)), original.size());
|
||||
std::size_t trim_size = std::min<std::size_t>(
|
||||
static_cast<std::size_t>(std::max<int>(get_items_expected_max(), 1)), original.size());
|
||||
if(original.size() != trim_size) {
|
||||
res.assign(original.end() - static_cast<results_t::difference_type>(trim_size), original.end());
|
||||
}
|
||||
} break;
|
||||
case MultiOptionPolicy::TakeFirst: {
|
||||
size_t trim_size =
|
||||
std::min<size_t>(static_cast<size_t>(std::max<int>(get_items_expected_max(), 1)), original.size());
|
||||
std::size_t trim_size = std::min<std::size_t>(
|
||||
static_cast<std::size_t>(std::max<int>(get_items_expected_max(), 1)), original.size());
|
||||
if(original.size() != trim_size) {
|
||||
res.assign(original.begin(), original.begin() + static_cast<results_t::difference_type>(trim_size));
|
||||
}
|
||||
@ -1165,8 +1165,8 @@ class Option : public OptionBase<Option> {
|
||||
break;
|
||||
case MultiOptionPolicy::Throw:
|
||||
default: {
|
||||
auto num_min = static_cast<size_t>(get_items_expected_min());
|
||||
auto num_max = static_cast<size_t>(get_items_expected_max());
|
||||
auto num_min = static_cast<std::size_t>(get_items_expected_min());
|
||||
auto num_max = static_cast<std::size_t>(get_items_expected_max());
|
||||
if(num_min == 0) {
|
||||
num_min = 1;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ inline bool split_windows_style(const std::string ¤t, std::string &name, s
|
||||
// Splits a string into multiple long and short names
|
||||
inline std::vector<std::string> split_names(std::string current) {
|
||||
std::vector<std::string> output;
|
||||
size_t val;
|
||||
std::size_t val;
|
||||
while((val = current.find(",")) != std::string::npos) {
|
||||
output.push_back(trim_copy(current.substr(0, val)));
|
||||
current = current.substr(val + 1);
|
||||
|
@ -84,7 +84,7 @@ std::string join(const T &v, Callable func, std::string delim = ",") {
|
||||
/// Join a string in reverse order
|
||||
template <typename T> std::string rjoin(const T &v, std::string delim = ",") {
|
||||
std::ostringstream s;
|
||||
for(size_t start = 0; start < v.size(); start++) {
|
||||
for(std::size_t start = 0; start < v.size(); start++) {
|
||||
if(start > 0)
|
||||
s << delim;
|
||||
s << v[v.size() - start - 1];
|
||||
@ -141,7 +141,7 @@ inline std::string trim_copy(const std::string &str, const std::string &filter)
|
||||
return trim(s, filter);
|
||||
}
|
||||
/// Print a two part "help" string
|
||||
inline std::ostream &format_help(std::ostream &out, std::string name, std::string description, size_t wid) {
|
||||
inline std::ostream &format_help(std::ostream &out, std::string name, std::string description, std::size_t wid) {
|
||||
name = " " + name;
|
||||
out << std::setw(static_cast<int>(wid)) << std::left << name;
|
||||
if(!description.empty()) {
|
||||
@ -198,7 +198,7 @@ inline std::string remove_underscore(std::string str) {
|
||||
/// Find and replace a substring with another substring
|
||||
inline std::string find_and_replace(std::string str, std::string from, std::string to) {
|
||||
|
||||
size_t start_pos = 0;
|
||||
std::size_t start_pos = 0;
|
||||
|
||||
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||
str.replace(start_pos, from.length(), to);
|
||||
@ -259,7 +259,7 @@ inline std::ptrdiff_t find_member(std::string name,
|
||||
/// Find a trigger string and call a modify callable function that takes the current string and starting position of the
|
||||
/// trigger and returns the position in the string to search for the next trigger string
|
||||
template <typename Callable> inline std::string find_and_modify(std::string str, std::string trigger, Callable modify) {
|
||||
size_t start_pos = 0;
|
||||
std::size_t start_pos = 0;
|
||||
while((start_pos = str.find(trigger, start_pos)) != std::string::npos) {
|
||||
start_pos = modify(str, start_pos);
|
||||
}
|
||||
@ -333,7 +333,7 @@ inline std::string fix_newlines(std::string leader, std::string input) {
|
||||
/// then modifies the string to replace the equality with a space. This is needed
|
||||
/// to allow the split up function to work properly and is intended to be used with the find_and_modify function
|
||||
/// the return value is the offset+1 which is required by the find_and_modify function.
|
||||
inline size_t escape_detect(std::string &str, size_t offset) {
|
||||
inline std::size_t escape_detect(std::string &str, std::size_t offset) {
|
||||
auto next = str[offset + 1];
|
||||
if((next == '\"') || (next == '\'') || (next == '`')) {
|
||||
auto astart = str.find_last_of("-/ \"\'`", offset - 1);
|
||||
|
@ -40,7 +40,7 @@ class Timer {
|
||||
time_point start_;
|
||||
|
||||
/// This is the number of times cycles (print divides by this number)
|
||||
size_t cycles{1};
|
||||
std::size_t cycles{1};
|
||||
|
||||
public:
|
||||
/// Standard print function, this one is set by default
|
||||
@ -63,7 +63,7 @@ class Timer {
|
||||
double total_time;
|
||||
|
||||
start_ = clock::now();
|
||||
size_t n = 0;
|
||||
std::size_t n = 0;
|
||||
do {
|
||||
f();
|
||||
std::chrono::duration<double> elapsed = clock::now() - start_;
|
||||
@ -107,7 +107,7 @@ class Timer {
|
||||
std::string to_string() const { return time_print_(title_, make_time_str()); }
|
||||
|
||||
/// Division sets the number of cycles to divide by (no graphical change)
|
||||
Timer &operator/(size_t val) {
|
||||
Timer &operator/(std::size_t val) {
|
||||
cycles = val;
|
||||
return *this;
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ template <typename T,
|
||||
enable_if_t<classify_object<T>::value == object_category::integral_value, detail::enabler> = detail::dummy>
|
||||
bool lexical_cast(const std::string &input, T &output) {
|
||||
try {
|
||||
size_t n = 0;
|
||||
std::size_t n = 0;
|
||||
long long output_ll = std::stoll(input, &n, 0);
|
||||
output = static_cast<T>(output_ll);
|
||||
return n == input.size() && static_cast<long long>(output) == output_ll;
|
||||
@ -610,7 +610,7 @@ bool lexical_cast(const std::string &input, T &output) {
|
||||
return false; // std::stoull happily converts negative values to junk without any errors.
|
||||
|
||||
try {
|
||||
size_t n = 0;
|
||||
std::size_t n = 0;
|
||||
unsigned long long output_ll = std::stoull(input, &n, 0);
|
||||
output = static_cast<T>(output_ll);
|
||||
return n == input.size() && static_cast<unsigned long long>(output) == output_ll;
|
||||
@ -644,7 +644,7 @@ template <typename T,
|
||||
enable_if_t<classify_object<T>::value == object_category::floating_point, detail::enabler> = detail::dummy>
|
||||
bool lexical_cast(const std::string &input, T &output) {
|
||||
try {
|
||||
size_t n = 0;
|
||||
std::size_t n = 0;
|
||||
output = static_cast<T>(std::stold(input, &n));
|
||||
return n == input.size();
|
||||
} catch(const std::invalid_argument &) {
|
||||
@ -846,7 +846,7 @@ template <class T,
|
||||
detail::enabler> = detail::dummy>
|
||||
bool lexical_conversion(const std::vector<std ::string> &strings, T &output) {
|
||||
output.clear();
|
||||
for(size_t ii = 0; ii < strings.size(); ii += 2) {
|
||||
for(std::size_t ii = 0; ii < strings.size(); ii += 2) {
|
||||
|
||||
typename std::tuple_element<0, typename XC::value_type>::type v1;
|
||||
typename std::tuple_element<1, typename XC::value_type>::type v2;
|
||||
@ -938,9 +938,9 @@ bool lexical_conversion(const std::vector<std ::string> &strings, T &output) {
|
||||
bool retval = true;
|
||||
output.clear();
|
||||
std::vector<std::string> temp;
|
||||
size_t ii = 0;
|
||||
size_t icount = 0;
|
||||
size_t xcm = type_count<XC>::value;
|
||||
std::size_t ii = 0;
|
||||
std::size_t icount = 0;
|
||||
std::size_t xcm = type_count<XC>::value;
|
||||
while(ii < strings.size()) {
|
||||
temp.push_back(strings[ii]);
|
||||
++ii;
|
||||
|
@ -931,7 +931,7 @@ class AsNumberWithUnit : public Validator {
|
||||
}
|
||||
|
||||
std::string unit{unit_begin, input.end()};
|
||||
input.resize(static_cast<size_t>(std::distance(input.begin(), unit_begin)));
|
||||
input.resize(static_cast<std::size_t>(std::distance(input.begin(), unit_begin)));
|
||||
detail::trim(input);
|
||||
|
||||
if(opts & UNIT_REQUIRED && unit.empty()) {
|
||||
|
@ -527,12 +527,12 @@ TEST_F(TApp, GetOptionList) {
|
||||
const CLI::App &const_app = app; // const alias to force use of const-methods
|
||||
std::vector<const CLI::Option *> opt_list = const_app.get_options();
|
||||
|
||||
ASSERT_EQ(opt_list.size(), static_cast<size_t>(3));
|
||||
ASSERT_EQ(opt_list.size(), static_cast<std::size_t>(3));
|
||||
EXPECT_EQ(opt_list.at(1), flag);
|
||||
EXPECT_EQ(opt_list.at(2), opt);
|
||||
|
||||
std::vector<CLI::Option *> nonconst_opt_list = app.get_options();
|
||||
for(size_t i = 0; i < opt_list.size(); ++i) {
|
||||
for(std::size_t i = 0; i < opt_list.size(); ++i) {
|
||||
EXPECT_EQ(nonconst_opt_list.at(i), opt_list.at(i));
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ TEST(String, InvalidName) {
|
||||
|
||||
TEST(StringTools, Modify) {
|
||||
int cnt = 0;
|
||||
std::string newString = CLI::detail::find_and_modify("======", "=", [&cnt](std::string &str, size_t index) {
|
||||
std::string newString = CLI::detail::find_and_modify("======", "=", [&cnt](std::string &str, std::size_t index) {
|
||||
if((++cnt) % 2 == 0) {
|
||||
str[index] = ':';
|
||||
}
|
||||
@ -117,7 +117,7 @@ TEST(StringTools, Modify) {
|
||||
|
||||
TEST(StringTools, Modify2) {
|
||||
std::string newString =
|
||||
CLI::detail::find_and_modify("this is a string test", "is", [](std::string &str, size_t index) {
|
||||
CLI::detail::find_and_modify("this is a string test", "is", [](std::string &str, std::size_t index) {
|
||||
if((index > 1) && (str[index - 1] != ' ')) {
|
||||
str[index] = 'a';
|
||||
str[index + 1] = 't';
|
||||
@ -129,7 +129,7 @@ TEST(StringTools, Modify2) {
|
||||
|
||||
TEST(StringTools, Modify3) {
|
||||
// this picks up 3 sets of 3 after the 'b' then collapses the new first set
|
||||
std::string newString = CLI::detail::find_and_modify("baaaaaaaaaa", "aaa", [](std::string &str, size_t index) {
|
||||
std::string newString = CLI::detail::find_and_modify("baaaaaaaaaa", "aaa", [](std::string &str, std::size_t index) {
|
||||
str.erase(index, 3);
|
||||
str.insert(str.begin(), 'a');
|
||||
return 0u;
|
||||
@ -525,8 +525,8 @@ TEST(CheckedMultiply, Int) {
|
||||
}
|
||||
|
||||
TEST(CheckedMultiply, SizeT) {
|
||||
size_t a = 10;
|
||||
size_t b = 20;
|
||||
std::size_t a = 10;
|
||||
std::size_t b = 20;
|
||||
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
|
||||
ASSERT_EQ(a, 200u);
|
||||
|
||||
@ -540,25 +540,25 @@ TEST(CheckedMultiply, SizeT) {
|
||||
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
|
||||
ASSERT_EQ(a, 0u);
|
||||
|
||||
a = std::numeric_limits<size_t>::max();
|
||||
a = std::numeric_limits<std::size_t>::max();
|
||||
b = 1u;
|
||||
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
|
||||
ASSERT_EQ(a, std::numeric_limits<size_t>::max());
|
||||
ASSERT_EQ(a, std::numeric_limits<std::size_t>::max());
|
||||
|
||||
a = std::numeric_limits<size_t>::max();
|
||||
a = std::numeric_limits<std::size_t>::max();
|
||||
b = 2u;
|
||||
ASSERT_FALSE(CLI::detail::checked_multiply(a, b));
|
||||
ASSERT_EQ(a, std::numeric_limits<size_t>::max());
|
||||
ASSERT_EQ(a, std::numeric_limits<std::size_t>::max());
|
||||
|
||||
a = std::numeric_limits<size_t>::max();
|
||||
b = std::numeric_limits<size_t>::max();
|
||||
a = std::numeric_limits<std::size_t>::max();
|
||||
b = std::numeric_limits<std::size_t>::max();
|
||||
ASSERT_FALSE(CLI::detail::checked_multiply(a, b));
|
||||
ASSERT_EQ(a, std::numeric_limits<size_t>::max());
|
||||
ASSERT_EQ(a, std::numeric_limits<std::size_t>::max());
|
||||
|
||||
a = std::numeric_limits<size_t>::max() / 100;
|
||||
a = std::numeric_limits<std::size_t>::max() / 100;
|
||||
b = 99u;
|
||||
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
|
||||
ASSERT_EQ(a, std::numeric_limits<size_t>::max() / 100u * 99u);
|
||||
ASSERT_EQ(a, std::numeric_limits<std::size_t>::max() / 100u * 99u);
|
||||
}
|
||||
|
||||
TEST(CheckedMultiply, Float) {
|
||||
|
@ -675,14 +675,14 @@ TEST_F(ManyGroups, Moving) {
|
||||
}
|
||||
|
||||
struct ManyGroupsPreTrigger : public ManyGroups {
|
||||
size_t triggerMain{0u}, trigger1{87u}, trigger2{34u}, trigger3{27u};
|
||||
std::size_t triggerMain{0u}, trigger1{87u}, trigger2{34u}, trigger3{27u};
|
||||
ManyGroupsPreTrigger() {
|
||||
remove_required();
|
||||
app.preparse_callback([this](size_t count) { triggerMain = count; });
|
||||
app.preparse_callback([this](std::size_t count) { triggerMain = count; });
|
||||
|
||||
g1->preparse_callback([this](size_t count) { trigger1 = count; });
|
||||
g2->preparse_callback([this](size_t count) { trigger2 = count; });
|
||||
g3->preparse_callback([this](size_t count) { trigger3 = count; });
|
||||
g1->preparse_callback([this](std::size_t count) { trigger1 = count; });
|
||||
g2->preparse_callback([this](std::size_t count) { trigger2 = count; });
|
||||
g3->preparse_callback([this](std::size_t count) { trigger3 = count; });
|
||||
}
|
||||
};
|
||||
|
||||
@ -747,8 +747,8 @@ TEST_F(ManyGroupsPreTrigger, PreTriggerTestsSubcommand) {
|
||||
g2->add_subcommand("sub2")->fallthrough();
|
||||
g3->add_subcommand("sub3")->fallthrough();
|
||||
|
||||
size_t subtrigger;
|
||||
sub1->preparse_callback([&subtrigger](size_t count) { subtrigger = count; });
|
||||
std::size_t subtrigger;
|
||||
sub1->preparse_callback([&subtrigger](std::size_t count) { subtrigger = count; });
|
||||
args = {"sub1"};
|
||||
run();
|
||||
EXPECT_EQ(triggerMain, 1u);
|
||||
|
@ -245,13 +245,15 @@ TEST_F(TApp, CallbackOrder) {
|
||||
std::vector<std::string> cb;
|
||||
app.parse_complete_callback([&cb]() { cb.push_back("ac1"); });
|
||||
app.final_callback([&cb]() { cb.push_back("ac2"); });
|
||||
auto sub1 = app.add_subcommand("sub1")
|
||||
->parse_complete_callback([&cb]() { cb.push_back("c1"); })
|
||||
->preparse_callback([&cb](size_t v1) { cb.push_back(std::string("pc1-") + std::to_string(v1)); });
|
||||
auto sub2 = app.add_subcommand("sub2")
|
||||
->final_callback([&cb]() { cb.push_back("c2"); })
|
||||
->preparse_callback([&cb](size_t v1) { cb.push_back(std::string("pc2-") + std::to_string(v1)); });
|
||||
app.preparse_callback([&cb](size_t v1) { cb.push_back(std::string("pa-") + std::to_string(v1)); });
|
||||
auto sub1 =
|
||||
app.add_subcommand("sub1")
|
||||
->parse_complete_callback([&cb]() { cb.push_back("c1"); })
|
||||
->preparse_callback([&cb](std::size_t v1) { cb.push_back(std::string("pc1-") + std::to_string(v1)); });
|
||||
auto sub2 =
|
||||
app.add_subcommand("sub2")
|
||||
->final_callback([&cb]() { cb.push_back("c2"); })
|
||||
->preparse_callback([&cb](std::size_t v1) { cb.push_back(std::string("pc2-") + std::to_string(v1)); });
|
||||
app.preparse_callback([&cb](std::size_t v1) { cb.push_back(std::string("pa-") + std::to_string(v1)); });
|
||||
|
||||
app.add_option("--opt1");
|
||||
sub1->add_flag("--sub1opt");
|
||||
|
Loading…
x
Reference in New Issue
Block a user