Commit ed85f04a1b4e6a472f8973971c1f6c69b8afc02f

Authored by Rosen Penev
Committed by GitHub
1 parent 834fb999

clang-tidy stuff (#266)

Several clang-tidy improvements.
Showing 1 changed file with 19 additions and 16 deletions
include/cxxopts.hpp
@@ -82,7 +82,7 @@ namespace cxxopts @@ -82,7 +82,7 @@ namespace cxxopts
82 82
83 namespace cxxopts 83 namespace cxxopts
84 { 84 {
85 - typedef icu::UnicodeString String; 85 + using String = icu::UnicodeString;
86 86
87 inline 87 inline
88 String 88 String
@@ -217,7 +217,7 @@ namespace std @@ -217,7 +217,7 @@ namespace std
217 217
218 namespace cxxopts 218 namespace cxxopts
219 { 219 {
220 - typedef std::string String; 220 + using String = std::string;
221 221
222 template <typename T> 222 template <typename T>
223 T 223 T
@@ -562,7 +562,7 @@ namespace cxxopts @@ -562,7 +562,7 @@ namespace cxxopts
562 { 562 {
563 template <typename U> 563 template <typename U>
564 void 564 void
565 - operator()(bool, U, const std::string&) {} 565 + operator()(bool, U, const std::string&) const {}
566 }; 566 };
567 567
568 template <typename T, typename U> 568 template <typename T, typename U>
@@ -1030,9 +1030,9 @@ namespace cxxopts @@ -1030,9 +1030,9 @@ namespace cxxopts
1030 1030
1031 OptionDetails(const OptionDetails& rhs) 1031 OptionDetails(const OptionDetails& rhs)
1032 : m_desc(rhs.m_desc) 1032 : m_desc(rhs.m_desc)
  1033 + , m_value(rhs.m_value->clone())
1033 , m_count(rhs.m_count) 1034 , m_count(rhs.m_count)
1034 { 1035 {
1035 - m_value = rhs.m_value->clone();  
1036 } 1036 }
1037 1037
1038 OptionDetails(OptionDetails&& rhs) = default; 1038 OptionDetails(OptionDetails&& rhs) = default;
@@ -1236,8 +1236,7 @@ namespace cxxopts @@ -1236,8 +1236,7 @@ namespace cxxopts
1236 { 1236 {
1237 public: 1237 public:
1238 1238
1239 - ParseResult() {}  
1240 - 1239 + ParseResult() = default;
1241 ParseResult(const ParseResult&) = default; 1240 ParseResult(const ParseResult&) = default;
1242 1241
1243 ParseResult(NameHashMap&& keys, ParsedHashMap&& values, std::vector<KeyValue> sequential, std::vector<std::string>&& unmatched_args) 1242 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&amp; a, PositionalListIterator&amp; n @@ -1840,9 +1839,9 @@ OptionParser::consume_positional(const std::string&amp; a, PositionalListIterator&amp; n
1840 auto iter = m_options.find(*next); 1839 auto iter = m_options.find(*next);
1841 if (iter != m_options.end()) 1840 if (iter != m_options.end())
1842 { 1841 {
1843 - auto& result = m_parsed[iter->second->hash()];  
1844 if (!iter->second->value().is_container()) 1842 if (!iter->second->value().is_container())
1845 { 1843 {
  1844 + auto& result = m_parsed[iter->second->hash()];
1846 if (result.count() == 0) 1845 if (result.count() == 0)
1847 { 1846 {
1848 add_to_option(iter, *next, a); 1847 add_to_option(iter, *next, a);
@@ -1898,7 +1897,7 @@ OptionParser::parse(int argc, const char* const* argv) @@ -1898,7 +1897,7 @@ OptionParser::parse(int argc, const char* const* argv)
1898 { 1897 {
1899 int current = 1; 1898 int current = 1;
1900 bool consume_remaining = false; 1899 bool consume_remaining = false;
1901 - PositionalListIterator next_positional = m_positional.begin(); 1900 + auto next_positional = m_positional.begin();
1902 1901
1903 std::vector<std::string> unmatched; 1902 std::vector<std::string> unmatched;
1904 1903
@@ -1932,7 +1931,7 @@ OptionParser::parse(int argc, const char* const* argv) @@ -1932,7 +1931,7 @@ OptionParser::parse(int argc, const char* const* argv)
1932 } 1931 }
1933 else 1932 else
1934 { 1933 {
1935 - unmatched.push_back(argv[current]); 1934 + unmatched.emplace_back(argv[current]);
1936 } 1935 }
1937 //if we return from here then it was parsed successfully, so continue 1936 //if we return from here then it was parsed successfully, so continue
1938 } 1937 }
@@ -1987,7 +1986,7 @@ OptionParser::parse(int argc, const char* const* argv) @@ -1987,7 +1986,7 @@ OptionParser::parse(int argc, const char* const* argv)
1987 if (m_allow_unrecognised) 1986 if (m_allow_unrecognised)
1988 { 1987 {
1989 // keep unrecognised options in argument list, skip to next argument 1988 // keep unrecognised options in argument list, skip to next argument
1990 - unmatched.push_back(argv[current]); 1989 + unmatched.emplace_back(argv[current]);
1991 ++current; 1990 ++current;
1992 continue; 1991 continue;
1993 } 1992 }
@@ -2040,7 +2039,7 @@ OptionParser::parse(int argc, const char* const* argv) @@ -2040,7 +2039,7 @@ OptionParser::parse(int argc, const char* const* argv)
2040 2039
2041 //adjust argv for any that couldn't be swallowed 2040 //adjust argv for any that couldn't be swallowed
2042 while (current != argc) { 2041 while (current != argc) {
2043 - unmatched.push_back(argv[current]); 2042 + unmatched.emplace_back(argv[current]);
2044 ++current; 2043 ++current;
2045 } 2044 }
2046 } 2045 }
@@ -2235,12 +2234,16 @@ void @@ -2235,12 +2234,16 @@ void
2235 Options::generate_all_groups_help(String& result) const 2234 Options::generate_all_groups_help(String& result) const
2236 { 2235 {
2237 std::vector<std::string> all_groups; 2236 std::vector<std::string> all_groups;
2238 - all_groups.reserve(m_help.size());  
2239 2237
2240 - for (const auto& group : m_help)  
2241 - {  
2242 - all_groups.push_back(group.first);  
2243 - } 2238 + std::transform(
  2239 + m_help.begin(),
  2240 + m_help.end(),
  2241 + std::back_inserter(all_groups),
  2242 + [] (const std::map<std::string, HelpGroupDetails>::value_type& group)
  2243 + {
  2244 + return group.first;
  2245 + }
  2246 + );
2244 2247
2245 generate_group_help(result, all_groups); 2248 generate_group_help(result, all_groups);
2246 } 2249 }