gnucash master: Refactor std::any_of into lambda
Christopher Lam
clam at code.gnucash.org
Tue Mar 14 06:22:48 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/6db868ab (commit)
from https://github.com/Gnucash/gnucash/commit/be88133b (commit)
commit 6db868ab64e8618d330cb43b155ad48f0ebfd302
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Mar 14 18:18:56 2023 +0800
Refactor std::any_of into lambda
Rewrite 16cc218097 to avoid the lambda accessing external variable
is_req_column_type
diff --git a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
index 1e3093ede4..102f28229a 100644
--- a/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
+++ b/gnucash/import-export/csv-imp/assistant-csv-price-import.cpp
@@ -1683,13 +1683,16 @@ void CsvImpPriceAssist::preview_refresh_table ()
preview_style_column (i, combostore);
auto column_types = price_imp->column_types_price();
- GncPricePropType req_column_type;
- auto is_req_column_type = [&req_column_type] (GncPricePropType column_type)->bool
- { return column_type == req_column_type; };
+ auto any_of_type = [](std::vector<GncPricePropType>& column_types,
+ GncPricePropType req_column_type) -> bool
+ {
+ return std::any_of (column_types.begin(), column_types.end(),
+ [&req_column_type](GncPricePropType column_type) -> bool
+ { return column_type == req_column_type; });
+ };
// look for a namespace column, clear the commodity combo
- req_column_type = GncPricePropType::FROM_NAMESPACE; // Used by is_column_type()
- if (std::any_of (column_types.begin(), column_types.end(), is_req_column_type))
+ if (any_of_type (column_types, GncPricePropType::FROM_NAMESPACE))
{
g_signal_handlers_block_by_func (commodity_selector, (gpointer) csv_price_imp_preview_commodity_sel_cb, this);
set_commodity_for_combo (GTK_COMBO_BOX(commodity_selector), nullptr);
@@ -1697,8 +1700,7 @@ void CsvImpPriceAssist::preview_refresh_table ()
}
// look for a symbol column, clear the commodity combo
- req_column_type = GncPricePropType::FROM_SYMBOL; // Used by is_column_type()
- if (std::any_of (column_types.begin(), column_types.end(), is_req_column_type))
+ if (any_of_type (column_types, GncPricePropType::FROM_SYMBOL))
{
g_signal_handlers_block_by_func (commodity_selector, (gpointer) csv_price_imp_preview_commodity_sel_cb, this);
set_commodity_for_combo (GTK_COMBO_BOX(commodity_selector), nullptr);
@@ -1706,8 +1708,7 @@ void CsvImpPriceAssist::preview_refresh_table ()
}
// look for a currency column, clear the currency combo
- req_column_type = GncPricePropType::TO_CURRENCY; // Used by is_column_type()
- if (std::any_of (column_types.begin(), column_types.end(), is_req_column_type))
+ if (any_of_type (column_types, GncPricePropType::TO_CURRENCY))
{
g_signal_handlers_block_by_func (currency_selector, (gpointer) csv_price_imp_preview_currency_sel_cb, this);
set_commodity_for_combo (GTK_COMBO_BOX(currency_selector), nullptr);
Summary of changes:
.../csv-imp/assistant-csv-price-import.cpp | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
More information about the gnucash-changes
mailing list