1
1
#include < algorithm>
2
- #include < array>
3
2
#include < list>
4
3
#include < cassert>
5
4
#include < string>
6
5
#include < set>
7
6
#include < limits>
7
+ #include < utility>
8
8
9
9
#include " argparse.hpp"
10
10
#include " argparse_util.hpp"
@@ -16,16 +16,16 @@ namespace argparse {
16
16
* ArgumentParser
17
17
*/
18
18
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) )
21
21
, formatter_(new DefaultFormatter())
22
22
, os_(os)
23
23
{
24
24
prog (prog_name);
25
25
argument_groups_.push_back (ArgumentGroup (" arguments" ));
26
26
}
27
27
28
- ArgumentParser& ArgumentParser::prog (std::string prog_name, bool basename_only) {
28
+ ArgumentParser& ArgumentParser::prog (const std::string& prog_name, bool basename_only) {
29
29
if (basename_only) {
30
30
prog_ = basename (prog_name);
31
31
} else {
@@ -35,17 +35,17 @@ namespace argparse {
35
35
}
36
36
37
37
ArgumentParser& ArgumentParser::version (std::string version_str) {
38
- version_ = version_str;
38
+ version_ = std::move ( version_str) ;
39
39
return *this ;
40
40
}
41
41
42
42
ArgumentParser& ArgumentParser::epilog (std::string epilog_str) {
43
- epilog_ = epilog_str;
43
+ epilog_ = std::move ( epilog_str) ;
44
44
return *this ;
45
45
}
46
46
47
47
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) ));
49
49
return argument_groups_[argument_groups_.size () - 1 ];
50
50
}
51
51
@@ -72,7 +72,7 @@ namespace argparse {
72
72
void ArgumentParser::parse_args_throw (int argc, const char * const * argv) {
73
73
std::vector<std::string> arg_strs;
74
74
for (int i = 1 ; i < argc; ++i) {
75
- arg_strs.push_back (argv[i]);
75
+ arg_strs.emplace_back (argv[i]);
76
76
}
77
77
78
78
parse_args_throw (arg_strs);
@@ -241,7 +241,7 @@ namespace argparse {
241
241
} else if (arg->nargs () == ' +' || arg->nargs () == ' *' ) {
242
242
if (arg->nargs () == ' +' ) {
243
243
assert (nargs_read >= 1 );
244
- assert (values.size () >= 1 );
244
+ assert (! values.empty () );
245
245
}
246
246
247
247
for (const auto & value : values) {
@@ -410,11 +410,11 @@ namespace argparse {
410
410
* ArgumentGroup
411
411
*/
412
412
ArgumentGroup::ArgumentGroup (std::string name_str)
413
- : name_(name_str)
413
+ : name_(std::move( name_str) )
414
414
{}
415
415
416
416
ArgumentGroup& ArgumentGroup::epilog (std::string str) {
417
- epilog_ = str;
417
+ epilog_ = std::move ( str) ;
418
418
return *this ;
419
419
}
420
420
std::string ArgumentGroup::name () const { return name_; }
@@ -425,10 +425,10 @@ namespace argparse {
425
425
* Argument
426
426
*/
427
427
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) ) {
430
430
431
- if (long_opt_.size () < 1 ) {
431
+ if (long_opt_.empty () ) {
432
432
throw ArgParseError (" Argument must be at least one character long" );
433
433
}
434
434
@@ -445,7 +445,7 @@ namespace argparse {
445
445
}
446
446
447
447
Argument& Argument::help (std::string help_str) {
448
- help_ = help_str;
448
+ help_ = std::move ( help_str) ;
449
449
return *this ;
450
450
}
451
451
@@ -476,12 +476,12 @@ namespace argparse {
476
476
}
477
477
478
478
Argument& Argument::metavar (std::string metavar_str) {
479
- metavar_ = metavar_str;
479
+ metavar_ = std::move ( metavar_str) ;
480
480
return *this ;
481
481
}
482
482
483
483
Argument& Argument::choices (std::vector<std::string> choice_values) {
484
- choices_ = choice_values;
484
+ choices_ = std::move ( choice_values) ;
485
485
return *this ;
486
486
}
487
487
@@ -536,7 +536,7 @@ namespace argparse {
536
536
}
537
537
538
538
Argument& Argument::group_name (std::string grp) {
539
- group_name_ = grp;
539
+ group_name_ = std::move ( grp) ;
540
540
return *this ;
541
541
}
542
542
0 commit comments