From 4545e685d885ff3c47c8a4d75438054fc1cd1fec Mon Sep 17 00:00:00 2001 From: alexnik Date: Tue, 3 Mar 2026 08:01:34 -0800 Subject: [PATCH 1/2] get rid of nested bind, and a little bit more --- adobe/algorithm/gather.hpp | 7 +++++-- adobe/algorithm/sort.hpp | 20 +++++++++++++------- adobe/algorithm/sorted.hpp | 32 ++++++++++++++++++++------------ adobe/arg_stream.hpp | 12 ++++-------- source/adam.cpp | 30 +++++++++++++++++------------- source/eve_evaluate.cpp | 28 ++++++++++++++++++++++++---- 6 files changed, 83 insertions(+), 46 deletions(-) diff --git a/adobe/algorithm/gather.hpp b/adobe/algorithm/gather.hpp index cbbae199..617c6e5b 100644 --- a/adobe/algorithm/gather.hpp +++ b/adobe/algorithm/gather.hpp @@ -16,6 +16,7 @@ #include // for std::table_partition #include +#include #include // for boost::begin(range) #include // for boost::end(range) @@ -81,8 +82,10 @@ std::pair gather(Iter first, Iter last, Iter pivot, Pred pred) { return std::make_pair( std::stable_partition( first, pivot, - std::bind(std::logical_not(), std::bind(pred, std::placeholders::_1))), - std::stable_partition(pivot, last, std::bind(pred, std::placeholders::_1))); + [&](auto&& v) -> bool { return !pred(std::forward(v)); }), + std::stable_partition(pivot, last, [&](auto&& v) -> bool { + return pred(std::forward(v)); + })); } /**************************************************************************************************/ diff --git a/adobe/algorithm/sort.hpp b/adobe/algorithm/sort.hpp index 3fe09f09..0a4cd6f5 100644 --- a/adobe/algorithm/sort.hpp +++ b/adobe/algorithm/sort.hpp @@ -48,7 +48,9 @@ inline void sort(RandomAccessRange& range) { */ template inline void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) { - return std::sort(first, last, std::bind(comp, std::placeholders::_1, std::placeholders::_2)); + return std::sort(first, last, [comp](const auto& a, const auto& b) { + return std::invoke(comp, a, b); + }); } /*! @@ -63,7 +65,9 @@ template // P models UnaryFunction(value_type(I)) -> T inline void sort(R& r, C c, P p) { - return adobe::sort( - boost::begin(r), boost::end(r), - std::bind(c, std::bind(p, std::placeholders::_1), std::bind(p, std::placeholders::_2))); + return adobe::sort(boost::begin(r), boost::end(r), c, p); } /*! @@ -109,7 +111,9 @@ inline void stable_sort(RandomAccessRange& range) { template inline void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) { return std::stable_sort(first, last, - std::bind(comp, std::placeholders::_1, std::placeholders::_2)); + [&](const auto& a, const auto& b) { + return std::invoke(comp, a, b); + }); } /*! @@ -154,7 +158,9 @@ inline void partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp) { return std::partial_sort_copy(first, last, result_first, result_last, - std::bind(comp, std::placeholders::_1, std::placeholders::_2)); + [&](const auto& a, const auto& b) { + return std::invoke(comp, a, b); + }); } /*! diff --git a/adobe/algorithm/sorted.hpp b/adobe/algorithm/sorted.hpp index 37074e72..1a3d1324 100644 --- a/adobe/algorithm/sorted.hpp +++ b/adobe/algorithm/sorted.hpp @@ -15,8 +15,6 @@ #include #include -#include - /**************************************************************************************************/ namespace adobe { @@ -35,9 +33,12 @@ template (), - std::bind(o, std::placeholders::_1, std::placeholders::_2))); + f = std::adjacent_find( + f, l, + [&](const auto& first, const auto& next) { + return !std::invoke(o, first, next); + }); + if (f != l) ++f; return f; @@ -63,9 +64,10 @@ template (), - std::bind(o, std::placeholders::_1, std::placeholders::_2))) == l; + f, l, + [&](const auto& first, const auto& next) { + return !std::invoke(o, first, next); + }) == l; } /**************************************************************************************************/ @@ -88,10 +90,16 @@ template // P models UnaryFunction(value_type(I)) -> T inline bool is_sorted(I f, I l, C c, P p) { - return std::adjacent_find(f, l, - std::bind(std::logical_not(), - std::bind(c, std::bind(p, std::placeholders::_1), - std::bind(p, std::placeholders::_2)))) == l; + return std::adjacent_find( + f, l, + [&](const auto& first, const auto& next) { + return !std::invoke( + c, + std::invoke(p, first), + std::invoke(p, next) + ); + } + ) == l; } /**************************************************************************************************/ diff --git a/adobe/arg_stream.hpp b/adobe/arg_stream.hpp index 56cc1afb..f756da97 100644 --- a/adobe/arg_stream.hpp +++ b/adobe/arg_stream.hpp @@ -24,8 +24,6 @@ #include #include -#include - #include // ADOBE_HAS_TYPE/ADOBE_HAS_MEMBER #include @@ -111,14 +109,12 @@ struct traits { namespace detail { -template ::has_eof_memberfunction>::type* dummy = nullptr> +template ::has_eof_memberfunction>* dummy = nullptr> static bool eof_check(ArgStream& as) { return as.eof(); } -template ::has_eof_memberfunction>::type* dummy = nullptr> +template ::has_eof_memberfunction>* dummy = nullptr> static bool eof_check(ArgStream& as) { return false; } @@ -453,13 +449,13 @@ struct with_transform { bool eof() { return detail::eof_check(argstream); } template - R transforming_get(typename boost::enable_if>::type* dummy = 0) { + R transforming_get(std::enable_if::value>* dummy = nullptr) { typedef typename Transformer::template arg_stream_inverse_lookup::type Rfrom; return transformer.template arg_stream_transform( arg_stream::get_next_arg(argstream)); } template - R transforming_get(typename boost::disable_if>::type* dummy = 0) { + R transforming_get(std::enable_if::value>* dummy = nullptr) { return arg_stream::get_next_arg(argstream); } diff --git a/source/adam.cpp b/source/adam.cpp index 4f0b673b..a2f9a64d 100644 --- a/source/adam.cpp +++ b/source/adam.cpp @@ -739,7 +739,7 @@ void sheet_t::implementation_t::add_output(name_t name, const line_position_t& p // REVISIT (sparent) : Non-transactional on failure. cell_set_m.push_back(cell_t( access_output, name, - std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression), + [&, this]() { return calculate_expression(position, expression); }, cell_set_m.size(), nullptr)); output_index_m.insert(cell_set_m.back()); @@ -765,8 +765,9 @@ void sheet_t::implementation_t::add_interface(name_t name, bool linked, if (initializer_expression.size()) { cell_set_m.push_back(cell_t(name, linked, - std::bind(&implementation_t::calculate_expression, - std::ref(*this), position1, initializer_expression), + [&, this]() { + return calculate_expression(position1, initializer_expression); + }, cell_set_m.size())); } else { cell_set_m.push_back(cell_t(name, linked, cell_t::calculator_t(), cell_set_m.size())); @@ -781,12 +782,13 @@ void sheet_t::implementation_t::add_interface(name_t name, bool linked, if (expression.size()) { // REVISIT (sparent) : Non-transactional on failure. cell_set_m.push_back(cell_t(access_interface_output, name, - std::bind(&implementation_t::calculate_expression, - std::ref(*this), position2, expression), + [&, this]() { + return calculate_expression(position2, expression); + }, cell_set_m.size(), &cell_set_m.back())); } else { cell_set_m.push_back(cell_t(access_interface_output, name, - std::bind(&implementation_t::get, std::ref(*this), name), + [&, this]() { return get(name); }, cell_set_m.size(), &cell_set_m.back())); } output_index_m.insert(cell_set_m.back()); @@ -810,7 +812,7 @@ void sheet_t::implementation_t::add_interface(name_t name, any_regular_t initial cell.priority_m = ++priority_high_m; cell_set_m.push_back(cell_t(access_interface_output, name, - std::bind(&implementation_t::get, std::ref(*this), name), + [&, this]() { return get(name); }, cell_set_m.size(), &cell)); output_index_m.insert(cell_set_m.back()); @@ -852,7 +854,7 @@ void sheet_t::implementation_t::add_logic(name_t logic, const line_position_t& p const array_t& expression) { cell_set_m.push_back(cell_t( access_logic, logic, - std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression), + [&, this]() { return calculate_expression(position, expression); }, cell_set_m.size(), nullptr)); if (!name_index_m.insert(cell_set_m.back()).second) { @@ -868,7 +870,7 @@ void sheet_t::implementation_t::add_invariant(name_t name, const line_position_t // REVISIT (sparent) : Non-transactional on failure. cell_set_m.push_back(cell_t( access_invariant, name, - std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression), + [&, this]() { return calculate_expression(position, expression); }, cell_set_m.size(), nullptr)); output_index_m.insert(cell_set_m.back()); @@ -953,8 +955,11 @@ sheet_t::connection_t sheet_t::implementation_t::monitor_enabled(name_t n, const monitor(active_m.test(iter->cell_set_pos_m) || (value_accessed_m.test(iter->cell_set_pos_m) && (touch_set & priority_accessed_m).any())); - return monitor_enabled_m.connect(std::bind(&sheet_t::implementation_t::enabled_filter, this, - touch_set, iter->cell_set_pos_m, monitor, _1, _2)); + std::size_t iter_pos = iter->cell_set_pos_m; + return monitor_enabled_m.connect( + [&, this](const cell_bits_t& a, const cell_bits_t& b) { + enabled_filter(touch_set, iter_pos, monitor, a, b); + }); } /**************************************************************************************************/ @@ -1006,8 +1011,7 @@ sheet_t::implementation_t::monitor_contributing(name_t n, const dictionary_t& ma monitor(contributing_set(mark, iter->contributing_m)); return iter->monitor_contributing_m.connect( - std::bind(monitor, std::bind(&sheet_t::implementation_t::contributing_set, std::ref(*this), - mark, _1))); + [this, mark, monitor](const cell_bits_t& bits) { monitor(contributing_set(mark, bits)); }); } /**************************************************************************************************/ diff --git a/source/eve_evaluate.cpp b/source/eve_evaluate.cpp index 93912ed5..dc01dba0 100644 --- a/source/eve_evaluate.cpp +++ b/source/eve_evaluate.cpp @@ -200,9 +200,26 @@ eve_callback_suite_t bind_layout(const bind_layout_proc_t& proc, sheet_t& sheet, eve_callback_suite_t suite; suite.add_view_proc_m = - std::bind(proc, _1, _3, std::bind(&evaluate_named_arguments, std::ref(evaluator), _4)); - suite.add_cell_proc_m = std::bind(&add_cell, std::ref(sheet), _1, _2, _3, _4); - suite.add_relation_proc_m = std::bind(&add_relation, std::ref(sheet), _1, _2, _3, _4); + [&evaluator, &proc](const eve_callback_suite_t::position_t& parent, const line_position_t& /* parse_location */, + name_t name, const array_t& parameters, const std::string& /* brief */, + const std::string& /* detailed */) -> eve_callback_suite_t::position_t { + return proc(parent, name, evaluate_named_arguments(evaluator, parameters)); + }; + suite.add_cell_proc_m = + [&sheet](adobe::eve_callback_suite_t::cell_type_t type, + adobe::name_t name, const adobe::line_position_t& position, + const adobe::array_t& init_or_expr, + const std::string& /* brief */, const std::string& /* detailed */) -> void { + add_cell(sheet, type, name, position, init_or_expr); + }; + suite.add_relation_proc_m = + [&sheet](const adobe::line_position_t& position, + const adobe::array_t& conditional, + const adobe::eve_callback_suite_t::relation_t* first, + const adobe::eve_callback_suite_t::relation_t* last, + const std::string& /* brief */, const std::string& /* detailed */) -> void { + add_relation(sheet, position, conditional, first, last); + }; suite.add_interface_proc_m = [&sheet](name_t name, bool linked, const line_position_t& position1, const array_t& initializer, const line_position_t& position2, @@ -210,7 +227,10 @@ eve_callback_suite_t bind_layout(const bind_layout_proc_t& proc, sheet_t& sheet, const std::string& /* detailed */) -> void { sheet.add_interface(name, linked, position1, initializer, position2, expression); }; - suite.finalize_sheet_proc_m = std::bind(&sheet_t::update, std::ref(sheet)); + suite.finalize_sheet_proc_m = + [&sheet]() -> void { + sheet.update(); + }; return suite; } From 0e9af8bee63e6ce2dc4b4b887b5a444a5f01ac64 Mon Sep 17 00:00:00 2001 From: Sasha Nikiforov Date: Tue, 3 Mar 2026 12:13:09 -0800 Subject: [PATCH 2/2] address comments --- adobe/algorithm/gather.hpp | 6 +++--- adobe/algorithm/sort.hpp | 8 ++++---- adobe/algorithm/sorted.hpp | 6 +++--- source/adam.cpp | 19 +++++++++---------- source/eve_evaluate.cpp | 2 +- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/adobe/algorithm/gather.hpp b/adobe/algorithm/gather.hpp index 617c6e5b..32bf733b 100644 --- a/adobe/algorithm/gather.hpp +++ b/adobe/algorithm/gather.hpp @@ -82,9 +82,9 @@ std::pair gather(Iter first, Iter last, Iter pivot, Pred pred) { return std::make_pair( std::stable_partition( first, pivot, - [&](auto&& v) -> bool { return !pred(std::forward(v)); }), - std::stable_partition(pivot, last, [&](auto&& v) -> bool { - return pred(std::forward(v)); + [&](const auto& v) -> bool { return !std::invoke(pred, v); }), + std::stable_partition(pivot, last, [&](const auto& v) -> bool { + return std::invoke(pred, v); })); } diff --git a/adobe/algorithm/sort.hpp b/adobe/algorithm/sort.hpp index 0a4cd6f5..9fc5a66d 100644 --- a/adobe/algorithm/sort.hpp +++ b/adobe/algorithm/sort.hpp @@ -48,7 +48,7 @@ inline void sort(RandomAccessRange& range) { */ template inline void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) { - return std::sort(first, last, [comp](const auto& a, const auto& b) { + return std::sort(first, last, [&comp](const auto& a, const auto& b) { return std::invoke(comp, a, b); }); } @@ -65,7 +65,7 @@ template inline void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) { return std::stable_sort(first, last, - [&](const auto& a, const auto& b) { + [&comp](const auto& a, const auto& b) { return std::invoke(comp, a, b); }); } @@ -158,7 +158,7 @@ inline void partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp) { return std::partial_sort_copy(first, last, result_first, result_last, - [&](const auto& a, const auto& b) { + [&comp](const auto& a, const auto& b) { return std::invoke(comp, a, b); }); } diff --git a/adobe/algorithm/sorted.hpp b/adobe/algorithm/sorted.hpp index 1a3d1324..4ba9076d 100644 --- a/adobe/algorithm/sorted.hpp +++ b/adobe/algorithm/sorted.hpp @@ -35,7 +35,7 @@ I sorted(I f, I l, O o) { f = std::adjacent_find( f, l, - [&](const auto& first, const auto& next) { + [&o](const auto& first, const auto& next) { return !std::invoke(o, first, next); }); @@ -65,7 +65,7 @@ template cell_set_pos_m) || (value_accessed_m.test(iter->cell_set_pos_m) && (touch_set & priority_accessed_m).any())); - std::size_t iter_pos = iter->cell_set_pos_m; return monitor_enabled_m.connect( - [&, this](const cell_bits_t& a, const cell_bits_t& b) { + [touch_set, iter_pos = iter->cell_set_pos_m, monitor, this](const cell_bits_t& a, const cell_bits_t& b) { enabled_filter(touch_set, iter_pos, monitor, a, b); }); } @@ -1011,7 +1010,7 @@ sheet_t::implementation_t::monitor_contributing(name_t n, const dictionary_t& ma monitor(contributing_set(mark, iter->contributing_m)); return iter->monitor_contributing_m.connect( - [this, mark, monitor](const cell_bits_t& bits) { monitor(contributing_set(mark, bits)); }); + [mark, monitor, this](const cell_bits_t& bits) { monitor(contributing_set(mark, bits)); }); } /**************************************************************************************************/ diff --git a/source/eve_evaluate.cpp b/source/eve_evaluate.cpp index dc01dba0..202f9e6f 100644 --- a/source/eve_evaluate.cpp +++ b/source/eve_evaluate.cpp @@ -200,7 +200,7 @@ eve_callback_suite_t bind_layout(const bind_layout_proc_t& proc, sheet_t& sheet, eve_callback_suite_t suite; suite.add_view_proc_m = - [&evaluator, &proc](const eve_callback_suite_t::position_t& parent, const line_position_t& /* parse_location */, + [&evaluator, proc](const eve_callback_suite_t::position_t& parent, const line_position_t& /* parse_location */, name_t name, const array_t& parameters, const std::string& /* brief */, const std::string& /* detailed */) -> eve_callback_suite_t::position_t { return proc(parent, name, evaluate_named_arguments(evaluator, parameters));