diff --git a/common/arg.cpp b/common/arg.cpp index 430ab45dfe26e..022e45f50816e 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -60,25 +60,25 @@ static std::string read_file(const std::string & fname) { return content; } -common_arg & common_arg::set_examples(std::initializer_list examples) { +common_arg && common_arg::set_examples(std::initializer_list examples) { this->examples = examples; - return *this; + return std::move(*this); } -common_arg & common_arg::set_excludes(std::initializer_list excludes) { +common_arg && common_arg::set_excludes(std::initializer_list excludes) { this->excludes = excludes; - return *this; + return std::move(*this); } -common_arg & common_arg::set_env(const char * env) { +common_arg && common_arg::set_env(const char * env) { help = help + "\n(env: " + env + ")"; this->env = env; - return *this; + return std::move(*this); } -common_arg & common_arg::set_sparam() { +common_arg && common_arg::set_sparam() { is_sparam = true; - return *this; + return std::move(*this); } bool common_arg::in_example(enum llama_example ex) { @@ -717,9 +717,9 @@ common_params_context common_params_parser_init(common_params & params, llama_ex * - if LLAMA_EXAMPLE_* is set (other than COMMON), we only show the option in the corresponding example * - if both {LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_*,} are set, we will prioritize the LLAMA_EXAMPLE_* matching current example */ - auto add_opt = [&](common_arg arg) { + auto add_opt = [&](common_arg && arg) { if ((arg.in_example(ex) || arg.in_example(LLAMA_EXAMPLE_COMMON)) && !arg.is_exclude(ex)) { - ctx_arg.options.push_back(std::move(arg)); + ctx_arg.options.emplace_back(std::move(arg)); } }; diff --git a/common/arg.h b/common/arg.h index 7ab7e2cea43cc..8a7c77af56d15 100644 --- a/common/arg.h +++ b/common/arg.h @@ -53,10 +53,10 @@ struct common_arg { void (*handler)(common_params & params, const std::string &, const std::string &) ) : args(args), value_hint(value_hint), value_hint_2(value_hint_2), help(help), handler_str_str(handler) {} - common_arg & set_examples(std::initializer_list examples); - common_arg & set_excludes(std::initializer_list excludes); - common_arg & set_env(const char * env); - common_arg & set_sparam(); + common_arg && set_examples(std::initializer_list examples); + common_arg && set_excludes(std::initializer_list excludes); + common_arg && set_env(const char * env); + common_arg && set_sparam(); bool in_example(enum llama_example ex); bool is_exclude(enum llama_example ex); bool get_value_from_env(std::string & output) const;