clang-tidy stuff (#266)

Several clang-tidy improvements.
This commit is contained in:
Rosen Penev 2021-01-18 22:05:09 -08:00 committed by GitHub
parent 834fb9999b
commit ed85f04a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,7 +82,7 @@ namespace cxxopts
namespace cxxopts namespace cxxopts
{ {
typedef icu::UnicodeString String; using String = icu::UnicodeString;
inline inline
String String
@ -217,7 +217,7 @@ namespace std
namespace cxxopts namespace cxxopts
{ {
typedef std::string String; using String = std::string;
template <typename T> template <typename T>
T T
@ -562,7 +562,7 @@ namespace cxxopts
{ {
template <typename U> template <typename U>
void void
operator()(bool, U, const std::string&) {} operator()(bool, U, const std::string&) const {}
}; };
template <typename T, typename U> template <typename T, typename U>
@ -1030,9 +1030,9 @@ namespace cxxopts
OptionDetails(const OptionDetails& rhs) OptionDetails(const OptionDetails& rhs)
: m_desc(rhs.m_desc) : m_desc(rhs.m_desc)
, m_value(rhs.m_value->clone())
, m_count(rhs.m_count) , m_count(rhs.m_count)
{ {
m_value = rhs.m_value->clone();
} }
OptionDetails(OptionDetails&& rhs) = default; OptionDetails(OptionDetails&& rhs) = default;
@ -1236,8 +1236,7 @@ namespace cxxopts
{ {
public: public:
ParseResult() {} ParseResult() = default;
ParseResult(const ParseResult&) = default; ParseResult(const ParseResult&) = default;
ParseResult(NameHashMap&& keys, ParsedHashMap&& values, std::vector<KeyValue> sequential, std::vector<std::string>&& unmatched_args) ParseResult(NameHashMap&& keys, ParsedHashMap&& values, std::vector<KeyValue> sequential, std::vector<std::string>&& unmatched_args)
@ -1840,9 +1839,9 @@ OptionParser::consume_positional(const std::string& a, PositionalListIterator& n
auto iter = m_options.find(*next); auto iter = m_options.find(*next);
if (iter != m_options.end()) if (iter != m_options.end())
{ {
auto& result = m_parsed[iter->second->hash()];
if (!iter->second->value().is_container()) if (!iter->second->value().is_container())
{ {
auto& result = m_parsed[iter->second->hash()];
if (result.count() == 0) if (result.count() == 0)
{ {
add_to_option(iter, *next, a); add_to_option(iter, *next, a);
@ -1898,7 +1897,7 @@ OptionParser::parse(int argc, const char* const* argv)
{ {
int current = 1; int current = 1;
bool consume_remaining = false; bool consume_remaining = false;
PositionalListIterator next_positional = m_positional.begin(); auto next_positional = m_positional.begin();
std::vector<std::string> unmatched; std::vector<std::string> unmatched;
@ -1932,7 +1931,7 @@ OptionParser::parse(int argc, const char* const* argv)
} }
else else
{ {
unmatched.push_back(argv[current]); unmatched.emplace_back(argv[current]);
} }
//if we return from here then it was parsed successfully, so continue //if we return from here then it was parsed successfully, so continue
} }
@ -1987,7 +1986,7 @@ OptionParser::parse(int argc, const char* const* argv)
if (m_allow_unrecognised) if (m_allow_unrecognised)
{ {
// keep unrecognised options in argument list, skip to next argument // keep unrecognised options in argument list, skip to next argument
unmatched.push_back(argv[current]); unmatched.emplace_back(argv[current]);
++current; ++current;
continue; continue;
} }
@ -2040,7 +2039,7 @@ OptionParser::parse(int argc, const char* const* argv)
//adjust argv for any that couldn't be swallowed //adjust argv for any that couldn't be swallowed
while (current != argc) { while (current != argc) {
unmatched.push_back(argv[current]); unmatched.emplace_back(argv[current]);
++current; ++current;
} }
} }
@ -2235,12 +2234,16 @@ void
Options::generate_all_groups_help(String& result) const Options::generate_all_groups_help(String& result) const
{ {
std::vector<std::string> all_groups; std::vector<std::string> all_groups;
all_groups.reserve(m_help.size());
for (const auto& group : m_help) std::transform(
{ m_help.begin(),
all_groups.push_back(group.first); m_help.end(),
} std::back_inserter(all_groups),
[] (const std::map<std::string, HelpGroupDetails>::value_type& group)
{
return group.first;
}
);
generate_group_help(result, all_groups); generate_group_help(result, all_groups);
} }