mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
clang-format
This commit is contained in:
parent
282f9ebf91
commit
6964cccd2f
@ -78,9 +78,8 @@ struct is_streamable : std::false_type {};
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_streamable<
|
struct is_streamable<
|
||||||
T,
|
T, std::conditional_t<
|
||||||
std::conditional_t<false,
|
false, decltype(std::declval<std::ostream>() << std::declval<T>()),
|
||||||
decltype(std::declval<std::ostream>() << std::declval<T>()),
|
|
||||||
void>> : std::true_type {};
|
void>> : std::true_type {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -90,11 +89,9 @@ template <typename T>
|
|||||||
static constexpr bool is_representable_v =
|
static constexpr bool is_representable_v =
|
||||||
is_streamable_v<T> || is_container_v<T>;
|
is_streamable_v<T> || is_container_v<T>;
|
||||||
|
|
||||||
|
|
||||||
constexpr size_t repr_max_container_size = 5;
|
constexpr size_t repr_max_container_size = 5;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> std::string repr(T const &val) {
|
||||||
std::string repr(T const &val) {
|
|
||||||
if constexpr (std::is_convertible_v<T, std::string_view>) {
|
if constexpr (std::is_convertible_v<T, std::string_view>) {
|
||||||
return '"' + std::string{std::string_view{val}} + '"';
|
return '"' + std::string{std::string_view{val}} + '"';
|
||||||
} else if constexpr (is_streamable_v<T>) {
|
} else if constexpr (is_streamable_v<T>) {
|
||||||
@ -142,7 +139,7 @@ template <> constexpr bool standard_unsigned_integer<unsigned long int> = true;
|
|||||||
template <>
|
template <>
|
||||||
constexpr bool standard_unsigned_integer<unsigned long long int> = true;
|
constexpr bool standard_unsigned_integer<unsigned long long int> = true;
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr bool standard_integer =
|
constexpr bool standard_integer =
|
||||||
@ -249,7 +246,7 @@ template <> constexpr auto generic_strtod<float> = strtof;
|
|||||||
template <> constexpr auto generic_strtod<double> = strtod;
|
template <> constexpr auto generic_strtod<double> = strtod;
|
||||||
template <> constexpr auto generic_strtod<long double> = strtold;
|
template <> constexpr auto generic_strtod<long double> = strtold;
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
template <class T> inline auto do_strtod(std::string const &s) -> T {
|
template <class T> inline auto do_strtod(std::string const &s) -> T {
|
||||||
if (isspace(static_cast<unsigned char>(s[0])) || s[0] == '+')
|
if (isspace(static_cast<unsigned char>(s[0])) || s[0] == '+')
|
||||||
@ -346,8 +343,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> Argument &default_value(T &&aDefaultValue) {
|
||||||
Argument &default_value(T&& aDefaultValue) {
|
|
||||||
mDefaultValueRepr = details::repr(aDefaultValue);
|
mDefaultValueRepr = details::repr(aDefaultValue);
|
||||||
mDefaultValue = std::forward<T>(aDefaultValue);
|
mDefaultValue = std::forward<T>(aDefaultValue);
|
||||||
return *this;
|
return *this;
|
||||||
@ -807,11 +803,10 @@ private:
|
|||||||
|
|
||||||
class ArgumentParser {
|
class ArgumentParser {
|
||||||
public:
|
public:
|
||||||
explicit ArgumentParser(std::string aProgramName = {}, std::string aVersion = "1.0")
|
explicit ArgumentParser(std::string aProgramName = {},
|
||||||
|
std::string aVersion = "1.0")
|
||||||
: mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) {
|
: mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) {
|
||||||
add_argument("-h", "--help")
|
add_argument("-h", "--help").help("shows help message and exits").nargs(0);
|
||||||
.help("shows help message and exits")
|
|
||||||
.nargs(0);
|
|
||||||
add_argument("-v", "--version")
|
add_argument("-v", "--version")
|
||||||
.help("prints version information and exits")
|
.help("prints version information and exits")
|
||||||
.nargs(0);
|
.nargs(0);
|
||||||
@ -907,7 +902,8 @@ public:
|
|||||||
* @throws std::logic_error if the option has no value
|
* @throws std::logic_error if the option has no value
|
||||||
* @throws std::bad_any_cast if the option is not of type T
|
* @throws std::bad_any_cast if the option is not of type T
|
||||||
*/
|
*/
|
||||||
template <typename T = std::string> T get(std::string_view aArgumentName) const {
|
template <typename T = std::string>
|
||||||
|
T get(std::string_view aArgumentName) const {
|
||||||
return (*this)[aArgumentName].get<T>();
|
return (*this)[aArgumentName].get<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user