Skip to content

Commit bc3effb

Browse files
Remove type aliases
1 parent d1f3577 commit bc3effb

File tree

2 files changed

+83
-89
lines changed

2 files changed

+83
-89
lines changed

args.hpp

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
namespace pgm
2121
{
2222

23-
// pull in often-used names from std::
24-
using std::move;
25-
using std::size_t;
26-
using std::string;
27-
using std::string_view;
28-
2923
////////////////////////////////////////////////////////////////////////////////
3024
// parsed values for an option or positional parameter
3125
struct argval
@@ -37,15 +31,15 @@ struct argval
3731

3832
auto const& values() const { return data_; }
3933
auto const& value() const { return data_.at(0); }
40-
auto const& value(size_t n) const { return data_.at(n); }
34+
auto const& value(std::size_t n) const { return data_.at(n); }
4135

42-
auto value_or(string_view def) const { return empty() ? string{def} : value(); }
36+
auto value_or(std::string_view def) const { return empty() ? std::string{def} : value(); }
4337

4438
private:
45-
std::vector<string> data_;
39+
std::vector<std::string> data_;
4640

4741
friend class args;
48-
void add(string val) { data_.push_back(move(val)); }
42+
void add(std::string val) { data_.push_back(std::move(val)); }
4943
};
5044

5145
////////////////////////////////////////////////////////////////////////////////
@@ -64,48 +58,48 @@ constexpr auto operator|(spec lhs, spec rhs);
6458
// program option
6559
struct option
6660
{
67-
string short_; // short option name
68-
string long_; // long option name
69-
string valname_; // name of the option value; eg, --opt-name=<value>
70-
string description_; // description
61+
std::string short_; // short option name
62+
std::string long_; // long option name
63+
std::string valname_; // name of the option value; eg, --opt-name=<value>
64+
std::string description_; // description
7165

72-
bool req_ = false; // mandatory (required) option
73-
bool mul_ = false; // can be specified multiple times
74-
bool optval_ = false; // option value is optional
66+
bool req_ = false; // mandatory (required) option
67+
bool mul_ = false; // can be specified multiple times
68+
bool optval_ = false; // option value is optional
7569

76-
argval values_; // parsed value(s)
70+
argval values_; // parsed value(s)
7771
};
7872

7973
////////////////////////////////////////////////////////////////////////////////
8074
// positional parameter
8175
struct param
8276
{
83-
string name_; // param name
84-
string description_; // description
77+
std::string name_; // param name
78+
std::string description_; // description
8579

86-
bool opt_ = false; // optional param
87-
bool mul_ = false; // can be specified multiple times
80+
bool opt_ = false; // optional param
81+
bool mul_ = false; // can be specified multiple times
8882

89-
argval values_; // parsed value(s)
83+
argval values_; // parsed value(s)
9084
};
9185

9286
////////////////////////////////////////////////////////////////////////////////
9387
// program argument (either option or param)
9488
struct arg
9589
{
96-
arg(string name1, string description) :
97-
arg{move(name1), spec{ }, move(description)}
90+
arg(std::string name1, std::string description) :
91+
arg{std::move(name1), spec{ }, std::move(description)}
9892
{ }
99-
arg(string name1, string name2, string description) :
100-
arg{move(name1), move(name2), spec{ }, move(description)}
93+
arg(std::string name1, std::string name2, std::string description) :
94+
arg{std::move(name1), std::move(name2), spec{ }, std::move(description)}
10195
{ }
102-
arg(string name1, string name2, string name3, string description) :
103-
arg{move(name1), move(name2), move(name3), spec{ }, move(description)}
96+
arg(std::string name1, std::string name2, std::string name3, std::string description) :
97+
arg{std::move(name1), std::move(name2), std::move(name3), spec{ }, std::move(description)}
10498
{ }
10599

106-
arg(string name1, spec, string description);
107-
arg(string name1, string name2, spec, string description);
108-
arg(string name1, string name2, string name3, spec, string description);
100+
arg(std::string name1, spec, std::string description);
101+
arg(std::string name1, std::string name2, spec, std::string description);
102+
arg(std::string name1, std::string name2, std::string name3, spec, std::string description);
109103

110104
auto is_option() const { return std::holds_alternative<option>(val_); }
111105
auto is_param() const { return std::holds_alternative<param>(val_); }
@@ -124,18 +118,18 @@ struct args
124118
args() = default;
125119
explicit args(std::initializer_list<arg> il)
126120
{
127-
for(auto& el : il) add(move(el));
121+
for(auto& el : il) add(std::move(el));
128122
}
129123

130124
void add(arg);
131125

132126
template<typename... Ts>
133127
void add(Ts&&... vs) { add(arg{ std::forward<Ts>(vs)... }); }
134128

135-
argval const& operator[](string_view) const;
129+
argval const& operator[](std::string_view) const;
136130

137131
void parse(int argc, char* argv[]);
138-
string usage(string_view program, string_view preamble = { }, string_view prologue = { }, string_view epilogue = { }) const;
132+
std::string usage(std::string_view program, std::string_view preamble = { }, std::string_view prologue = { }, std::string_view epilogue = { }) const;
139133

140134
private:
141135
std::vector<option> options_;
@@ -148,28 +142,28 @@ struct args
148142
////////////////////////////////////////////////////////////////////////////////
149143
struct argument_exception : std::invalid_argument
150144
{
151-
argument_exception(string_view what, string_view why) :
152-
std::invalid_argument{string{what}+": "+string{why}+"."}
145+
argument_exception(std::string_view what, std::string_view why) :
146+
std::invalid_argument{std::string{what}+": "+std::string{why}+"."}
153147
{ }
154148
};
155149

156150
struct invalid_definition : argument_exception
157151
{
158-
invalid_definition(string_view why) :
152+
invalid_definition(std::string_view why) :
159153
argument_exception{"Invalid definition", why}
160154
{ }
161155
};
162156

163157
struct invalid_argument : argument_exception
164158
{
165-
invalid_argument(string_view why) :
159+
invalid_argument(std::string_view why) :
166160
argument_exception{"Invalid argument", why}
167161
{ }
168162
};
169163

170164
struct missing_argument : argument_exception
171165
{
172-
missing_argument(string_view why) :
166+
missing_argument(std::string_view why) :
173167
argument_exception{"Missing argument", why}
174168
{ }
175169
};

0 commit comments

Comments
 (0)