From 985ea8666d973202e2644ecbe5a4dd13120c37c2 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Mon, 7 Feb 2022 14:33:24 -0700 Subject: [PATCH] Update identifier names for structs The new naming pattern is CamelCase for structs, except parse_number as a primarily callable interface. Trait structs are named Has*Traits and constexpr variables to the struct template are named Is*. Signed-off-by: Sean Robinson --- .clang-tidy | 4 +++- include/argparse/argparse.hpp | 36 ++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index fad0e71..88642ae 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,11 +8,13 @@ Checks: CheckOptions: - { key: readability-identifier-naming.ClassCase, value: CamelCase } - { key: readability-identifier-naming.ConstexprVariableCase, value: lower_case } + - { key: readability-identifier-naming.ConstexprVariableIgnoredRegexp, value: "^Is.+" } - { key: readability-identifier-naming.FunctionCase, value: lower_case } - { key: readability-identifier-naming.LocalVariableIgnoredRegexp, value: "^[a-z][a-z_]+" } - { key: readability-identifier-naming.NamespaceCase, value: lower_case } - { key: readability-identifier-naming.PrivateMemberPrefix, value: m } - - { key: readability-identifier-naming.StructCase, value: lower_case } + - { key: readability-identifier-naming.StructCase, value: CamelCase } + - { key: readability-identifier-naming.StructIgnoredRegexp, value: "parse_number" } - { key: readability-identifier-naming.VariableCase, value: camelBack } HeaderFilterRegex: '.*' diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index e64beeb..21a2c11 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -55,29 +55,31 @@ namespace argparse { namespace details { // namespace for helper methods -template struct is_container : std::false_type {}; +template +struct HasContainerTraits : std::false_type {}; -template <> struct is_container : std::false_type {}; +template <> struct HasContainerTraits : std::false_type {}; template -struct is_container< +struct HasContainerTraits< T, std::void_t().begin()), decltype(std::declval().end()), decltype(std::declval().size())>> : std::true_type {}; template -static constexpr bool is_container_v = is_container::value; +static constexpr bool IsContainer = HasContainerTraits::value; template -struct is_streamable : std::false_type {}; +struct HasStreamableTraits : std::false_type {}; template -struct is_streamable() - << std::declval())>> +struct HasStreamableTraits< + T, + std::void_t() << std::declval())>> : std::true_type {}; template -static constexpr bool is_streamable_v = is_streamable::value; +static constexpr bool IsStreamable = HasStreamableTraits::value; constexpr std::size_t repr_max_container_size = 5; @@ -86,7 +88,7 @@ template std::string repr(T const &val) { return val ? "true" : "false"; } else if constexpr (std::is_convertible_v) { return '"' + std::string{std::string_view{val}} + '"'; - } else if constexpr (is_container_v) { + } else if constexpr (IsContainer) { std::stringstream out; out << "{"; const auto size = val.size(); @@ -108,7 +110,7 @@ template std::string repr(T const &val) { } out << "}"; return out.str(); - } else if constexpr (is_streamable_v) { + } else if constexpr (IsStreamable) { std::stringstream out; out << val; return out.str(); @@ -176,7 +178,7 @@ enum class chars_format { general = fixed | scientific }; -struct consume_hex_prefix_result { +struct ConsumeHexPrefixResult { bool is_hexadecimal; std::string_view rest; }; @@ -184,7 +186,7 @@ struct consume_hex_prefix_result { using namespace std::literals; constexpr auto consume_hex_prefix(std::string_view s) - -> consume_hex_prefix_result { + -> ConsumeHexPrefixResult { if (starts_with("0x"sv, s) || starts_with("0X"sv, s)) { s.remove_prefix(2); return {true, s}; @@ -483,7 +485,7 @@ public: } } - struct action_apply { + struct ActionApply { void operator()(valued_action &f) { std::transform(first, last, std::back_inserter(self.mValues), f); } @@ -500,7 +502,7 @@ public: Iterator first, last; Argument &self; }; - std::visit(action_apply{start, end, *this}, mAction); + std::visit(ActionApply{start, end, *this}, mAction); return end; } if (mDefaultValue.has_value()) { @@ -591,7 +593,7 @@ public: * @throws std::logic_error in case of incompatible types */ template bool operator==(const T &aRhs) const { - if constexpr (!details::is_container_v) { + if constexpr (!details::IsContainer) { return get() == aRhs; } else { using ValueType = typename T::value_type; @@ -785,7 +787,7 @@ private: */ template T get() const { if (!mValues.empty()) { - if constexpr (details::is_container_v) { + if constexpr (details::IsContainer) { return any_cast_container(mValues); } else { return std::any_cast(mValues.front()); @@ -809,7 +811,7 @@ private: if (mValues.empty()) { return std::nullopt; } - if constexpr (details::is_container_v) { + if constexpr (details::IsContainer) { return any_cast_container(mValues); } return std::any_cast(mValues.front());