Moved tagpair-lambda up for better readability.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
tastytea 2019-09-23 21:52:10 +02:00
parent b4fb62b15a
commit da88eaf703
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 21 additions and 19 deletions

View File

@ -183,25 +183,27 @@ namespace remwharead
_out << "== Tags\n\n"; _out << "== Tags\n\n";
vector<tagpair> sortedtags(tags.size()); vector<tagpair> sortedtags(tags.size());
std::move(tags.begin(), tags.end(), sortedtags.begin()); std::move(tags.begin(), tags.end(), sortedtags.begin());
std::sort(sortedtags.begin(), sortedtags.end(),
[](const tagpair &a, tagpair &b) const auto compare_tags =
{ [](const tagpair &a, tagpair &b)
if (a.second.size() != b.second.size()) {
{ // Sort by number of occurrences if they are different. if (a.second.size() != b.second.size())
return a.second.size() > b.second.size(); { // Sort by number of occurrences if they are different.
} return a.second.size() > b.second.size();
else }
{ // Sort by tag names otherwise. else
std::locale loc; { // Sort by tag names otherwise.
const std::collate<char> &coll = const std::locale loc;
std::use_facet<std::collate<char>>(loc); const std::collate<char> &coll =
return (coll.compare( std::use_facet<std::collate<char>>(loc);
a.first.data(), a.first.data() return (
+ a.first.length(), coll.compare(
b.first.data(), b.first.data() a.first.data(), a.first.data() + a.first.length(),
+ b.first.length()) == -1); b.first.data(), b.first.data() + b.first.length())
} == -1);
}); }
};
std::sort(sortedtags.begin(), sortedtags.end(), compare_tags);
bool othertags = false; // Have we printed “Less used tags” already? bool othertags = false; // Have we printed “Less used tags” already?
for (const auto &tag : sortedtags) for (const auto &tag : sortedtags)