Skip to content

Commit 5bb569e

Browse files
committed
Do not use using namespace std
1 parent ca0ce9f commit 5bb569e

15 files changed

+705
-689
lines changed

Argo/ArgoArg.cc

+47-45
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import :std_module;
1111

1212
namespace Argo {
1313

14-
using namespace std;
15-
1614
/*!
1715
* ParserID which holds parser id
1816
* You can set int or string as id
@@ -80,12 +78,12 @@ struct String {
8078
}
8179
};
8280

83-
consteval explicit operator string() const {
84-
return string(str_, N);
81+
consteval explicit operator std::string() const {
82+
return std::string(str_, N);
8583
}
8684

87-
consteval explicit operator string_view() const {
88-
return string_view(str_, N);
85+
consteval explicit operator std::string_view() const {
86+
return std::string_view(str_, N);
8987
}
9088

9189
[[nodiscard]] consteval auto operator[](size_t n) const {
@@ -125,15 +123,18 @@ String(const char (&)[N]) -> String<N - 1>;
125123
*/
126124
template <class T>
127125
consteval auto get_type_name_base_type([[maybe_unused]] size_t n = 0) {
128-
if constexpr (is_same_v<T, bool>) {
126+
if constexpr (std::is_same_v<T, bool>) {
129127
return String("BOOL");
130-
} else if constexpr (is_integral_v<T>) {
128+
} else if constexpr (std::is_integral_v<T>) {
131129
return String("NUMBER");
132-
} else if constexpr (is_floating_point_v<T>) {
130+
} else if constexpr (std::is_floating_point_v<T>) {
133131
return String("FLOAT");
134-
} else if constexpr (is_same_v<T, const char*> or is_same_v<T, string> or
135-
is_same_v<T, string_view>) {
132+
} else if constexpr (std::is_same_v<T, const char*> or
133+
std::is_same_v<T, std::string> or
134+
std::is_same_v<T, std::string_view>) {
136135
return String("STRING");
136+
} else if constexpr (std::is_same_v<T, std::filesystem::path>) {
137+
return String("PATH");
137138
} else {
138139
return String("UNKNOWN");
139140
}
@@ -142,17 +143,17 @@ consteval auto get_type_name_base_type([[maybe_unused]] size_t n = 0) {
142143
template <class T, NArgs TNArgs>
143144
consteval auto get_base_type_name_form_stl() {
144145
if constexpr (is_array_v<T>) {
145-
return []<size_t... Is>(index_sequence<Is...>) consteval {
146+
return []<size_t... Is>(std::index_sequence<Is...>) consteval {
146147
return ((get_type_name_base_type<array_base_t<T>>(Is) + String(",")) +
147148
...);
148-
}(make_index_sequence<TNArgs.nargs>())
149+
}(std::make_index_sequence<TNArgs.nargs>())
149150
.removeTrail();
150151
} else if constexpr (is_vector_v<T>) {
151-
return []<size_t... Is>(index_sequence<Is...>) consteval {
152+
return []<size_t... Is>(std::index_sequence<Is...>) consteval {
152153
return ((get_type_name_base_type<vector_base_t<T>>(Is) + String(",")) +
153154
...)
154155
.removeTrail();
155-
}(make_index_sequence<TNArgs.nargs>());
156+
}(std::make_index_sequence<TNArgs.nargs>());
156157
} else if constexpr (is_tuple_v<T>) {
157158
return []<class... U>(type_sequence<U...>) consteval {
158159
return (((get_type_name_base_type<vector_base_t<U>>()) + String(",")) +
@@ -196,41 +197,42 @@ struct ArgTag {};
196197
*/
197198
template <class Type, ArgName Name, NArgs TNArgs, bool Required, ParserID ID>
198199
struct Arg : ArgTag {
199-
using type = //
200-
conditional_t< //
200+
using type = //
201+
std::conditional_t< //
201202
((TNArgs.nargs <= 1) && (TNArgs.nargs_char != '+') &&
202-
(TNArgs.nargs_char != '*')) //
203-
|| is_array_v<Type> //
204-
|| is_tuple_v<Type> //
205-
|| is_vector_v<Type>, //
206-
Type, //
207-
conditional_t< //
208-
(TNArgs.nargs > 1), //
209-
array<Type, static_cast<size_t>(TNArgs.nargs)>, //
210-
vector<Type> //
211-
> //
212-
>; //
213-
using baseType = conditional_t< //
214-
is_array_v<Type>, //
215-
array_base_t<Type>, //
216-
conditional_t< //
217-
is_vector_v<Type>, //
218-
vector_base_t<Type>, //
219-
Type //
220-
> //
203+
(TNArgs.nargs_char != '*')) //
204+
|| is_array_v<Type> //
205+
|| is_tuple_v<Type> //
206+
|| is_vector_v<Type>, //
207+
Type, //
208+
std::conditional_t< //
209+
(TNArgs.nargs > 1), //
210+
std::array<Type, static_cast<size_t>(TNArgs.nargs)>, //
211+
std::vector<Type> //
212+
> //
213+
>; //
214+
using baseType = std::conditional_t< //
215+
is_array_v<Type>, //
216+
array_base_t<Type>, //
217+
std::conditional_t< //
218+
is_vector_v<Type>, //
219+
vector_base_t<Type>, //
220+
Type //
221+
> //
221222
>;
222223
static constexpr auto name = Name;
223-
inline static string_view description{};
224+
inline static std::string_view description{};
224225
inline static bool assigned = false;
225226
inline static bool required = Required;
226227
inline static type value = {};
227228
inline static type defaultValue = {};
228229
inline static constexpr NArgs nargs = TNArgs;
229-
inline static function<type(string_view)> caster = nullptr;
230-
inline static function<void(const type& value, span<string_view>,
231-
string_view)>
230+
inline static std::function<type(std::string_view)> caster = nullptr;
231+
inline static std::function<void(
232+
const type& value, std::span<std::string_view>, std::string_view)>
232233
validator = nullptr;
233-
inline static function<void(type&, span<string_view>)> callback = nullptr;
234+
inline static std::function<void(type&, std::span<std::string_view>)>
235+
callback = nullptr;
234236
inline static constexpr auto typeName = get_type_name<type, TNArgs>();
235237
};
236238

@@ -242,9 +244,9 @@ struct FlagArg : FlagArgTag {
242244
using baseType = bool;
243245
static constexpr auto name = Name;
244246
inline static bool assigned = false;
245-
inline static string_view description{};
247+
inline static std::string_view description{};
246248
inline static type value = false;
247-
inline static function<void()> callback = nullptr;
249+
inline static std::function<void()> callback = nullptr;
248250
inline static constexpr auto typeName = String("");
249251
};
250252

@@ -256,9 +258,9 @@ struct HelpArg : HelpArgTag, FlagArgTag {
256258
using baseType = bool;
257259
static constexpr auto name = Name;
258260
inline static bool assigned = false;
259-
inline static string_view description = "Print help information";
261+
inline static std::string_view description = "Print help information";
260262
inline static type value = false;
261-
inline static function<void()> callback = nullptr;
263+
inline static std::function<void()> callback = nullptr;
262264
inline static constexpr auto typeName = String("");
263265
};
264266

Argo/ArgoArgName.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import :std_module;
1010

1111
namespace Argo {
1212

13-
using namespace std;
14-
1513
/*!
1614
* ArgName which holds argument name
1715
*/
@@ -38,7 +36,7 @@ struct ArgName {
3836
}
3937

4038
[[nodiscard]] ARGO_ALWAYS_INLINE constexpr auto getKey() const {
41-
return string_view(this->key_, this->key_len_);
39+
return std::string_view(this->key_, this->key_len_);
4240
}
4341

4442
[[nodiscard]] constexpr auto getKeyLen() const {
@@ -65,8 +63,8 @@ ArgName(const char (&)[N]) -> ArgName<N - 1>;
6563

6664
template <class T>
6765
concept ArgNameType = requires(T& x) {
68-
is_same_v<decltype(x.getKey()), string_view>;
69-
is_same_v<decltype(x.getShortName()), char>;
66+
std::is_same_v<decltype(x.getKey()), std::string_view>;
67+
std::is_same_v<decltype(x.getShortName()), char>;
7068
};
7169

7270
} // namespace Argo

Argo/ArgoExceptions.cc

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ import :std_module;
88

99
namespace Argo {
1010

11-
using namespace std;
12-
13-
export class ParserInternalError : public runtime_error {
11+
export class ParserInternalError : public std::runtime_error {
1412
public:
15-
explicit ParserInternalError(const string& msg) : runtime_error(msg) {}
13+
explicit ParserInternalError(const std::string& msg) : runtime_error(msg) {}
1614

1715
[[nodiscard]] const char* what() const noexcept override {
1816
return runtime_error::what();
1917
}
2018
};
2119

22-
export class ParseError : public runtime_error {
20+
export class ParseError : public std::runtime_error {
2321
public:
24-
explicit ParseError(const string& msg) : runtime_error(msg) {}
22+
explicit ParseError(const std::string& msg) : runtime_error(msg) {}
2523

2624
[[nodiscard]] const char* what() const noexcept override {
2725
return runtime_error::what();
@@ -31,9 +29,9 @@ export class ParseError : public runtime_error {
3129
/*!
3230
* InvalidArgument exception class
3331
*/
34-
export class InvalidArgument : public invalid_argument {
32+
export class InvalidArgument : public std::invalid_argument {
3533
public:
36-
explicit InvalidArgument(const string& msg) : invalid_argument(msg) {}
34+
explicit InvalidArgument(const std::string& msg) : invalid_argument(msg) {}
3735

3836
[[nodiscard]] const char* what() const noexcept override {
3937
return invalid_argument::what();
@@ -42,7 +40,7 @@ export class InvalidArgument : public invalid_argument {
4240

4341
export class ValidationError : public InvalidArgument {
4442
public:
45-
explicit ValidationError(const string& msg) : InvalidArgument(msg) {}
43+
explicit ValidationError(const std::string& msg) : InvalidArgument(msg) {}
4644

4745
[[nodiscard]] const char* what() const noexcept override {
4846
return InvalidArgument::what();

Argo/ArgoHelpGenerator.cc

+11-13
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,46 @@ import :std_module;
1212

1313
namespace Argo {
1414

15-
using namespace std;
16-
1715
struct ArgInfo {
18-
string_view name;
16+
std::string_view name;
1917
char shortName;
20-
string_view description;
18+
std::string_view description;
2119
bool required;
22-
string_view typeName;
20+
std::string_view typeName;
2321
};
2422

2523
template <class Args>
2624
ARGO_ALWAYS_INLINE constexpr auto HelpGenerator() {
27-
vector<ArgInfo> ret;
25+
std::vector<ArgInfo> ret;
2826
tuple_type_visit<Args>([&ret]<class T>(T) {
29-
if constexpr (derived_from<typename T::type, ArgTag>) {
27+
if constexpr (std::derived_from<typename T::type, ArgTag>) {
3028
ret.emplace_back(
3129
T::type::name.getKey().substr(0, T::type::name.getKeyLen()), //
3230
T::type::name.getShortName(), //
3331
T::type::description, //
3432
T::type::required, //
35-
string_view(T::type::typeName));
33+
std::string_view(T::type::typeName));
3634
} else {
3735
ret.emplace_back(
3836
T::type::name.getKey().substr(0, T::type::name.getKeyLen()), //
3937
T::type::name.getShortName(), //
4038
T::type::description, //
4139
false, //
42-
string_view(T::type::typeName));
40+
std::string_view(T::type::typeName));
4341
}
4442
});
4543
return ret;
4644
};
4745

4846
struct SubCommandInfo {
49-
string_view name;
50-
string_view description;
47+
std::string_view name;
48+
std::string_view description;
5149
};
5250

5351
template <class T>
5452
ARGO_ALWAYS_INLINE constexpr auto SubParserInfo(T subparsers) {
55-
vector<SubCommandInfo> ret{};
56-
if constexpr (!is_same_v<T, tuple<>>) {
53+
std::vector<SubCommandInfo> ret{};
54+
if constexpr (!std::is_same_v<T, std::tuple<>>) {
5755
apply(
5856
[&ret]<class... Parser>(Parser... parser) ARGO_ALWAYS_INLINE {
5957
(..., ret.emplace_back(parser.name.getKey(), parser.description));

Argo/ArgoInitializer.cc

+22-23
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import :std_module;
1414

1515
namespace Argo {
1616

17-
using namespace std;
18-
1917
struct ExplicitDefaultValueTag {};
2018

2119
template <class T>
@@ -31,10 +29,10 @@ struct ImplicitDefaultValue : ImplicitDefaultValueTag {
3129
};
3230

3331
struct Description {
34-
string_view description;
32+
std::string_view description;
3533
};
3634

37-
export ARGO_ALWAYS_INLINE constexpr auto description(string_view desc)
35+
export ARGO_ALWAYS_INLINE constexpr auto description(std::string_view desc)
3836
-> Description {
3937
return {.description = desc};
4038
}
@@ -57,22 +55,23 @@ ARGO_ALWAYS_INLINE constexpr auto ArgInitializer(Args... args) -> void {
5755
(
5856
[&args]() ARGO_ALWAYS_INLINE {
5957
using Arg = Arg<Type, Name, nargs, Required, ID>;
60-
if constexpr (is_same_v<Args, Description>) {
58+
if constexpr (std::is_same_v<Args, Description>) {
6159
Arg::description = args.description;
62-
} else if constexpr (derived_from<remove_cvref_t<Args>,
63-
Validation::ValidationBase>) {
64-
static_assert(is_invocable_v<Args, typename Arg::type,
65-
span<string_view>, string_view>,
60+
} else if constexpr (std::derived_from<std::remove_cvref_t<Args>,
61+
Validation::ValidationBase>) {
62+
static_assert(std::is_invocable_v<Args, typename Arg::type,
63+
std::span<std::string_view>,
64+
std::string_view>,
6665
"Invalid validator");
6766
Arg::validator = args;
68-
} else if constexpr (derived_from<remove_cvref_t<Args>,
69-
ImplicitDefaultValueTag>) {
67+
} else if constexpr (std::derived_from<std::remove_cvref_t<Args>,
68+
ImplicitDefaultValueTag>) {
7069
Arg::defaultValue = static_cast<Type>(args.implicit_default_value);
71-
} else if constexpr (derived_from<remove_cvref_t<Args>,
72-
ExplicitDefaultValueTag>) {
70+
} else if constexpr (std::derived_from<std::remove_cvref_t<Args>,
71+
ExplicitDefaultValueTag>) {
7372
Arg::value = static_cast<Type>(args.explicit_default_value);
74-
} else if constexpr (is_invocable_v<Args, typename Arg::type&,
75-
span<string_view>>) {
73+
} else if constexpr (std::is_invocable_v<Args, typename Arg::type&,
74+
std::span<std::string_view>>) {
7675
Arg::callback = args;
7776
} else {
7877
static_assert(false, "Invalid argument");
@@ -86,18 +85,18 @@ ARGO_ALWAYS_INLINE constexpr auto FlagArgInitializer(Args... args) -> void {
8685
(
8786
[&args]() ARGO_ALWAYS_INLINE {
8887
using FlagArg = FlagArg<Name, ID>;
89-
if constexpr (is_same_v<Args, Description>) {
88+
if constexpr (std::is_same_v<Args, Description>) {
9089
FlagArg::description = args.description;
91-
} else if constexpr (derived_from<remove_cvref_t<Args>,
92-
Validation::ValidationBase>) {
90+
} else if constexpr (std::derived_from<std::remove_cvref_t<Args>,
91+
Validation::ValidationBase>) {
9392
static_assert(false, "Flag cannot have validator");
94-
} else if constexpr (derived_from<remove_cvref_t<Args>,
95-
ImplicitDefaultValueTag>) {
93+
} else if constexpr (std::derived_from<std::remove_cvref_t<Args>,
94+
ImplicitDefaultValueTag>) {
9695
static_assert(false, "Flag cannot have implicit default value");
97-
} else if constexpr (derived_from<remove_cvref_t<Args>,
98-
ExplicitDefaultValueTag>) {
96+
} else if constexpr (std::derived_from<std::remove_cvref_t<Args>,
97+
ExplicitDefaultValueTag>) {
9998
static_assert(false, "Flag cannot have explicit default value");
100-
} else if constexpr (is_invocable_v<Args>) {
99+
} else if constexpr (std::is_invocable_v<Args>) {
101100
FlagArg::callback = args;
102101
} else {
103102
static_assert(false, "Invalid argument");

0 commit comments

Comments
 (0)