From d080dbcdaa9d181bcd12f207e28fb03e43b29df8 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Fri, 22 Nov 2024 18:58:32 +0200 Subject: [PATCH] Modernize functional code to use Lambdas --- src/cscout.cpp | 5 ----- src/filedetails.h | 2 +- src/fileid.h | 2 +- src/filequery.h | 2 +- src/funquery.h | 2 +- src/idquery.h | 2 +- src/macro.cpp | 4 ++-- src/metrics.h | 18 ++++++------------ src/pdtoken.cpp | 8 ++++---- 9 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/cscout.cpp b/src/cscout.cpp index b5c6666e..87fb13ed 100644 --- a/src/cscout.cpp +++ b/src/cscout.cpp @@ -1035,11 +1035,6 @@ filequery_page(FILE *of, void *p) html_tail(of); } -struct ignore : public binary_function { - inline bool operator()(int a, int b) const { return true; } -}; - - // Process a file query static void xfilequery_page(FILE *of, void *p) diff --git a/src/filedetails.h b/src/filedetails.h index 2fdbfb94..fc2d6288 100644 --- a/src/filedetails.h +++ b/src/filedetails.h @@ -75,7 +75,7 @@ class IncDetails { class Call; // Used to order Call sets by their function location in a file -struct function_file_order : public binary_function { +struct function_file_order { bool operator()(const Call *a, const Call *b) const; }; diff --git a/src/fileid.h b/src/fileid.h index 7a2d37c6..0422f91d 100644 --- a/src/fileid.h +++ b/src/fileid.h @@ -127,7 +127,7 @@ operator <(const class Fileid a, const class Fileid b) } // Can be used to order Fileid sets -struct fname_order : public binary_function { +struct fname_order { bool operator()(const Fileid &a, const Fileid &b) const { return a.get_path() < b.get_path(); } diff --git a/src/filequery.h b/src/filequery.h index 08900c23..b5064d22 100644 --- a/src/filequery.h +++ b/src/filequery.h @@ -55,7 +55,7 @@ class FileQuery : public Query { public: // Container comparison functor - class specified_order : public binary_function { + class specified_order { private: /* * Can only be an instance variable (per C++ PL 17.1.4.5) diff --git a/src/funquery.h b/src/funquery.h index 36250205..d67ea380 100644 --- a/src/funquery.h +++ b/src/funquery.h @@ -96,7 +96,7 @@ class FunQuery : public Query { string param_url() const; // // Container comparison functor - class specified_order : public binary_function { + class specified_order { private: /* * Can only be an instance variable (per C++ PL 17.1.4.5) diff --git a/src/idquery.h b/src/idquery.h index 20f313c5..4bbd4ade 100644 --- a/src/idquery.h +++ b/src/idquery.h @@ -124,7 +124,7 @@ class IdQuery : public Query { * Function object to compare IdProp identifier pointers * Will compare from end to start if sort_rev is set */ -struct idcmp : public binary_function { +struct idcmp { bool operator()(const IdProp::value_type *i1, const IdProp::value_type *i2) const { return Query::string_bi_compare(i1->second.get_id(), i2->second.get_id()); diff --git a/src/macro.cpp b/src/macro.cpp index d074f2cb..31d49c61 100644 --- a/src/macro.cpp +++ b/src/macro.cpp @@ -214,7 +214,7 @@ stringize(const PtokenSequence& ts) } } // Remove trailing spaces - res.erase((find_if(res.rbegin(), res.rend(), not1(ptr_fun(isspace)))).base(), res.end()); + res.erase(find_if(res.rbegin(), res.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), res.end()); return (Ptoken(STRING_LITERAL, res)); } @@ -315,7 +315,7 @@ void Macro::value_rtrim() { // Took me three hours to arrive at - value.erase((find_if(value.rbegin(), value.rend(), not1(mem_fun_ref(&Ptoken::is_space)))).base(), value.end()); + value.erase(find_if(value.rbegin(), value.rend(), [&](const Ptoken& token) { return !token.is_space(); }).base(), value.end()); } ostream& diff --git a/src/metrics.h b/src/metrics.h index 43c99b69..f605885f 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -476,39 +476,33 @@ class IdMetricsSummary { // Global metrics extern IdMetricsSummary id_msum; -struct add_one : public unary_function -{ +struct add_one { double operator()(double x) { return x + 1; } }; -struct add_n : public unary_function -{ +struct add_n { double n; add_n(double add) { n = add; } double operator()(double x) { return x + n; } }; -struct set_max : public unary_function -{ +struct set_max { double n; set_max(double newval) { n = newval; } double operator()(double x) { return x > n ? x : n; } }; -struct set_min : public unary_function -{ +struct set_min { double n; set_min(double newval) { n = newval; } double operator()(double x) { return (x < n && x > 0) ? x : n; } }; -struct get_max : public binary_function -{ +struct get_max { double operator()(double x, double y) { return (x < y) ? y : x; } }; -struct get_min : public binary_function -{ +struct get_min { double operator()(double x, double y) { return (x > y) ? y : x; } }; diff --git a/src/pdtoken.cpp b/src/pdtoken.cpp index 4c7c133f..c9ac4c32 100644 --- a/src/pdtoken.cpp +++ b/src/pdtoken.cpp @@ -365,10 +365,10 @@ process_defined() (i = i2 = find_if(i, eval_tokens.end(), [](const Ptoken &t) { return t.get_val() == "defined"; })) != eval_tokens.end(); ) { bool need_bracket = false; i2++; - arg = i2 = find_if(i2, eval_tokens.end(), not1(mem_fun_ref(&Ptoken::is_space))); + arg = i2 = find_if(i2, eval_tokens.end(), [&](const Ptoken& token) { return !token.is_space(); }); if (arg != eval_tokens.end() && (*arg).get_code() == '(') { i2++; - arg = i2 = find_if(i2, eval_tokens.end(), not1(mem_fun_ref(&Ptoken::is_space))); + arg = i2 = find_if(i2, eval_tokens.end(), [&](const Ptoken& token) { return !token.is_space(); }); need_bracket = true; } if (arg == eval_tokens.end() || (*arg).get_code() != IDENTIFIER) { @@ -383,7 +383,7 @@ process_defined() } if (need_bracket) { i2++; - last = find_if(i2, eval_tokens.end(), not1(mem_fun_ref(&Ptoken::is_space))); + last = find_if(i2, eval_tokens.end(), [&](const Ptoken& token) { return !token.is_space(); }); if (last == eval_tokens.end() || (*last).get_code() != ')') { /* * @error @@ -662,7 +662,7 @@ Pdtoken::process_include(bool next) tokens.push_back(t); } while (t.get_code() != EOF && t.get_code() != '\n'); // Remove leading space - tokens.erase(tokens.begin(), find_if(tokens.begin(), tokens.end(), not1(mem_fun_ref(&Ptoken::is_space)))); + tokens.erase(tokens.begin(), find_if(tokens.begin(), tokens.end(), [&](const Ptoken& token) { return !token.is_space(); })); if (tokens.size() == 0) { /* * @error