Skip to content

Commit

Permalink
Modernize functional code to use Lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Nov 22, 2024
1 parent b0d34a8 commit d080dbc
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 28 deletions.
5 changes: 0 additions & 5 deletions src/cscout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,11 +1035,6 @@ filequery_page(FILE *of, void *p)
html_tail(of);
}

struct ignore : public binary_function <int, int, bool> {
inline bool operator()(int a, int b) const { return true; }
};


// Process a file query
static void
xfilequery_page(FILE *of, void *p)
Expand Down
2 changes: 1 addition & 1 deletion src/filedetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <const Call *, const Call *, bool> {
struct function_file_order {
bool operator()(const Call *a, const Call *b) const;
};

Expand Down
2 changes: 1 addition & 1 deletion src/fileid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <const Fileid &, const Fileid &, bool> {
struct fname_order {
bool operator()(const Fileid &a, const Fileid &b) const {
return a.get_path() < b.get_path();
}
Expand Down
2 changes: 1 addition & 1 deletion src/filequery.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FileQuery : public Query {

public:
// Container comparison functor
class specified_order : public binary_function <const Fileid &, const Fileid &, bool> {
class specified_order {
private:
/*
* Can only be an instance variable (per C++ PL 17.1.4.5)
Expand Down
2 changes: 1 addition & 1 deletion src/funquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class FunQuery : public Query {
string param_url() const;
//
// Container comparison functor
class specified_order : public binary_function <const Call &, const Call &, bool> {
class specified_order {
private:
/*
* Can only be an instance variable (per C++ PL 17.1.4.5)
Expand Down
2 changes: 1 addition & 1 deletion src/idquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <const IdProp::value_type *, const IdProp::value_type *, bool> {
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());
Expand Down
4 changes: 2 additions & 2 deletions src/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ stringize(const PtokenSequence& ts)
}
}
// Remove trailing spaces
res.erase((find_if(res.rbegin(), res.rend(), not1(ptr_fun<int, int>(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));
}

Expand Down Expand Up @@ -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&
Expand Down
18 changes: 6 additions & 12 deletions src/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,39 +476,33 @@ class IdMetricsSummary {
// Global metrics
extern IdMetricsSummary id_msum;

struct add_one : public unary_function<double, double>
{
struct add_one {
double operator()(double x) { return x + 1; }
};

struct add_n : public unary_function<double, double>
{
struct add_n {
double n;
add_n(double add) { n = add; }
double operator()(double x) { return x + n; }
};

struct set_max : public unary_function<double, double>
{
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<double, double>
{
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<double, double, double>
{
struct get_max {
double operator()(double x, double y) { return (x < y) ? y : x; }
};

struct get_min : public binary_function<double, double, double>
{
struct get_min {
double operator()(double x, double y) { return (x > y) ? y : x; }
};

Expand Down
8 changes: 4 additions & 4 deletions src/pdtoken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d080dbc

Please sign in to comment.