11#include < algorithm>
2- #include < array>
32#include < list>
43#include < cassert>
54#include < string>
65#include < set>
76#include < limits>
7+ #include < utility>
88
99#include " argparse.hpp"
1010#include " argparse_util.hpp"
@@ -16,16 +16,16 @@ namespace argparse {
1616 * ArgumentParser
1717 */
1818
19- ArgumentParser::ArgumentParser (std::string prog_name, std::string description_str, std::ostream& os)
20- : description_(description_str)
19+ ArgumentParser::ArgumentParser (const std::string& prog_name, std::string description_str, std::ostream& os)
20+ : description_(std::move( description_str) )
2121 , formatter_(new DefaultFormatter())
2222 , os_(os)
2323 {
2424 prog (prog_name);
2525 argument_groups_.push_back (ArgumentGroup (" arguments" ));
2626 }
2727
28- ArgumentParser& ArgumentParser::prog (std::string prog_name, bool basename_only) {
28+ ArgumentParser& ArgumentParser::prog (const std::string& prog_name, bool basename_only) {
2929 if (basename_only) {
3030 prog_ = basename (prog_name);
3131 } else {
@@ -35,17 +35,17 @@ namespace argparse {
3535 }
3636
3737 ArgumentParser& ArgumentParser::version (std::string version_str) {
38- version_ = version_str;
38+ version_ = std::move ( version_str) ;
3939 return *this ;
4040 }
4141
4242 ArgumentParser& ArgumentParser::epilog (std::string epilog_str) {
43- epilog_ = epilog_str;
43+ epilog_ = std::move ( epilog_str) ;
4444 return *this ;
4545 }
4646
4747 ArgumentGroup& ArgumentParser::add_argument_group (std::string description_str) {
48- argument_groups_.push_back (ArgumentGroup (description_str));
48+ argument_groups_.push_back (ArgumentGroup (std::move ( description_str) ));
4949 return argument_groups_[argument_groups_.size () - 1 ];
5050 }
5151
@@ -72,7 +72,7 @@ namespace argparse {
7272 void ArgumentParser::parse_args_throw (int argc, const char * const * argv) {
7373 std::vector<std::string> arg_strs;
7474 for (int i = 1 ; i < argc; ++i) {
75- arg_strs.push_back (argv[i]);
75+ arg_strs.emplace_back (argv[i]);
7676 }
7777
7878 parse_args_throw (arg_strs);
@@ -241,7 +241,7 @@ namespace argparse {
241241 } else if (arg->nargs () == ' +' || arg->nargs () == ' *' ) {
242242 if (arg->nargs () == ' +' ) {
243243 assert (nargs_read >= 1 );
244- assert (values.size () >= 1 );
244+ assert (! values.empty () );
245245 }
246246
247247 for (const auto & value : values) {
@@ -410,11 +410,11 @@ namespace argparse {
410410 * ArgumentGroup
411411 */
412412 ArgumentGroup::ArgumentGroup (std::string name_str)
413- : name_(name_str)
413+ : name_(std::move( name_str) )
414414 {}
415415
416416 ArgumentGroup& ArgumentGroup::epilog (std::string str) {
417- epilog_ = str;
417+ epilog_ = std::move ( str) ;
418418 return *this ;
419419 }
420420 std::string ArgumentGroup::name () const { return name_; }
@@ -425,10 +425,10 @@ namespace argparse {
425425 * Argument
426426 */
427427 Argument::Argument (std::string long_opt, std::string short_opt)
428- : long_opt_(long_opt)
429- , short_opt_(short_opt) {
428+ : long_opt_(std::move( long_opt) )
429+ , short_opt_(std::move( short_opt) ) {
430430
431- if (long_opt_.size () < 1 ) {
431+ if (long_opt_.empty () ) {
432432 throw ArgParseError (" Argument must be at least one character long" );
433433 }
434434
@@ -445,7 +445,7 @@ namespace argparse {
445445 }
446446
447447 Argument& Argument::help (std::string help_str) {
448- help_ = help_str;
448+ help_ = std::move ( help_str) ;
449449 return *this ;
450450 }
451451
@@ -476,12 +476,12 @@ namespace argparse {
476476 }
477477
478478 Argument& Argument::metavar (std::string metavar_str) {
479- metavar_ = metavar_str;
479+ metavar_ = std::move ( metavar_str) ;
480480 return *this ;
481481 }
482482
483483 Argument& Argument::choices (std::vector<std::string> choice_values) {
484- choices_ = choice_values;
484+ choices_ = std::move ( choice_values) ;
485485 return *this ;
486486 }
487487
@@ -536,7 +536,7 @@ namespace argparse {
536536 }
537537
538538 Argument& Argument::group_name (std::string grp) {
539- group_name_ = grp;
539+ group_name_ = std::move ( grp) ;
540540 return *this ;
541541 }
542542
0 commit comments