Skip to content

Commit 26b88ed

Browse files
authored
Merge pull request #152 from venik/velo/no-nested-bind
Get rid of nested std::bind, and some boost removal
2 parents fbb1362 + 0e9af8b commit 26b88ed

6 files changed

Lines changed: 82 additions & 46 deletions

File tree

adobe/algorithm/gather.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <algorithm> // for std::table_partition
1818
#include <functional>
19+
#include <utility>
1920

2021
#include <boost/range/begin.hpp> // for boost::begin(range)
2122
#include <boost/range/end.hpp> // for boost::end(range)
@@ -81,8 +82,10 @@ std::pair<Iter, Iter> gather(Iter first, Iter last, Iter pivot, Pred pred) {
8182
return std::make_pair(
8283
std::stable_partition(
8384
first, pivot,
84-
std::bind(std::logical_not<bool>(), std::bind(pred, std::placeholders::_1))),
85-
std::stable_partition(pivot, last, std::bind(pred, std::placeholders::_1)));
85+
[&](const auto& v) -> bool { return !std::invoke(pred, v); }),
86+
std::stable_partition(pivot, last, [&](const auto& v) -> bool {
87+
return std::invoke(pred, v);
88+
}));
8689
}
8790

8891
/**************************************************************************************************/

adobe/algorithm/sort.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ inline void sort(RandomAccessRange& range) {
4848
*/
4949
template <class RandomAccessIterator, class Compare>
5050
inline void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) {
51-
return std::sort(first, last, std::bind(comp, std::placeholders::_1, std::placeholders::_2));
51+
return std::sort(first, last, [&comp](const auto& a, const auto& b) {
52+
return std::invoke(comp, a, b);
53+
});
5254
}
5355

5456
/*!
@@ -63,7 +65,9 @@ template <typename I, // I models RandomAccessIterator
6365
inline void sort(I f, I l, C c, P p) {
6466
return std::sort(
6567
f, l,
66-
std::bind(c, std::bind(p, std::placeholders::_1), std::bind(p, std::placeholders::_2)));
68+
[&p, &c](const auto& a, const auto& b) {
69+
return std::invoke(c, std::invoke(p, a), std::invoke(p, b));
70+
});
6771
}
6872

6973
/*!
@@ -76,9 +80,7 @@ template <typename R, // I models RandomAccessRange
7680
typename P>
7781
// P models UnaryFunction(value_type(I)) -> T
7882
inline void sort(R& r, C c, P p) {
79-
return adobe::sort(
80-
boost::begin(r), boost::end(r),
81-
std::bind(c, std::bind(p, std::placeholders::_1), std::bind(p, std::placeholders::_2)));
83+
return adobe::sort(boost::begin(r), boost::end(r), c, p);
8284
}
8385

8486
/*!
@@ -109,7 +111,9 @@ inline void stable_sort(RandomAccessRange& range) {
109111
template <class RandomAccessIterator, class Compare>
110112
inline void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) {
111113
return std::stable_sort(first, last,
112-
std::bind(comp, std::placeholders::_1, std::placeholders::_2));
114+
[&comp](const auto& a, const auto& b) {
115+
return std::invoke(comp, a, b);
116+
});
113117
}
114118

115119
/*!
@@ -154,7 +158,9 @@ inline void partial_sort_copy(InputIterator first, InputIterator last,
154158
RandomAccessIterator result_first, RandomAccessIterator result_last,
155159
Compare comp) {
156160
return std::partial_sort_copy(first, last, result_first, result_last,
157-
std::bind(comp, std::placeholders::_1, std::placeholders::_2));
161+
[&comp](const auto& a, const auto& b) {
162+
return std::invoke(comp, a, b);
163+
});
158164
}
159165

160166
/*!

adobe/algorithm/sorted.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <boost/range/begin.hpp>
1616
#include <boost/range/end.hpp>
1717

18-
#include <adobe/functional/operator.hpp>
19-
2018
/**************************************************************************************************/
2119

2220
namespace adobe {
@@ -35,9 +33,12 @@ template <typename I, // I models InputIterator
3533
// O models StrictWeakOrdering on value_type(I)
3634
I sorted(I f, I l, O o) {
3735

38-
f = std::adjacent_find(f, l,
39-
std::bind(std::logical_not<bool>(),
40-
std::bind(o, std::placeholders::_1, std::placeholders::_2)));
36+
f = std::adjacent_find(
37+
f, l,
38+
[&o](const auto& first, const auto& next) {
39+
return !std::invoke(o, first, next);
40+
});
41+
4142
if (f != l)
4243
++f;
4344
return f;
@@ -63,9 +64,10 @@ template <typename I, // I models InputIterator
6364
// O models StrictWeakOrdering on value_type(I)
6465
inline bool is_sorted(I f, I l, O o) {
6566
return std::adjacent_find(
66-
f, l,
67-
std::bind(std::logical_not<bool>(),
68-
std::bind(o, std::placeholders::_1, std::placeholders::_2))) == l;
67+
f, l,
68+
[&o](const auto& first, const auto& next) {
69+
return !std::invoke(o, first, next);
70+
}) == l;
6971
}
7072

7173
/**************************************************************************************************/
@@ -88,10 +90,16 @@ template <typename I, // I models ForwardIterator
8890
typename P>
8991
// P models UnaryFunction(value_type(I)) -> T
9092
inline bool is_sorted(I f, I l, C c, P p) {
91-
return std::adjacent_find(f, l,
92-
std::bind(std::logical_not<bool>(),
93-
std::bind(c, std::bind(p, std::placeholders::_1),
94-
std::bind(p, std::placeholders::_2)))) == l;
93+
return std::adjacent_find(
94+
f, l,
95+
[&c, &p](const auto& first, const auto& next) {
96+
return !std::invoke(
97+
c,
98+
std::invoke(p, first),
99+
std::invoke(p, next)
100+
);
101+
}
102+
) == l;
95103
}
96104

97105
/**************************************************************************************************/

adobe/arg_stream.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#include <boost/fusion/include/invoke.hpp>
2525
#include <boost/fusion/include/push_back.hpp>
2626

27-
#include <boost/utility/enable_if.hpp>
28-
2927
#include <adobe/type_inspection.hpp> // ADOBE_HAS_TYPE/ADOBE_HAS_MEMBER
3028
#include <adobe/typeinfo.hpp>
3129

@@ -111,14 +109,12 @@ struct traits {
111109

112110

113111
namespace detail {
114-
template <class ArgStream,
115-
typename boost::enable_if_c<traits<ArgStream>::has_eof_memberfunction>::type* dummy = nullptr>
112+
template <class ArgStream, std::enable_if_t<traits<ArgStream>::has_eof_memberfunction>* dummy = nullptr>
116113
static bool eof_check(ArgStream& as) {
117114
return as.eof();
118115
}
119116

120-
template <class ArgStream,
121-
typename boost::disable_if_c<traits<ArgStream>::has_eof_memberfunction>::type* dummy = nullptr>
117+
template <class ArgStream, std::enable_if_t<!traits<ArgStream>::has_eof_memberfunction>* dummy = nullptr>
122118
static bool eof_check(ArgStream& as) {
123119
return false;
124120
}
@@ -453,13 +449,13 @@ struct with_transform {
453449
bool eof() { return detail::eof_check(argstream); }
454450

455451
template <typename R>
456-
R transforming_get(typename boost::enable_if<has_transform<Transformer, R>>::type* dummy = 0) {
452+
R transforming_get(std::enable_if<has_transform<Transformer, R>::value>* dummy = nullptr) {
457453
typedef typename Transformer::template arg_stream_inverse_lookup<R>::type Rfrom;
458454
return transformer.template arg_stream_transform<R>(
459455
arg_stream::get_next_arg<Rfrom>(argstream));
460456
}
461457
template <typename R>
462-
R transforming_get(typename boost::disable_if<has_transform<Transformer, R>>::type* dummy = 0) {
458+
R transforming_get(std::enable_if<!has_transform<Transformer, R>::value>* dummy = nullptr) {
463459
return arg_stream::get_next_arg<R>(argstream);
464460
}
465461

source/adam.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ void sheet_t::implementation_t::add_output(name_t name, const line_position_t& p
739739
// REVISIT (sparent) : Non-transactional on failure.
740740
cell_set_m.push_back(cell_t(
741741
access_output, name,
742-
std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression),
742+
[position, expression, this]() { return calculate_expression(position, expression); },
743743
cell_set_m.size(), nullptr));
744744

745745
output_index_m.insert(cell_set_m.back());
@@ -765,8 +765,9 @@ void sheet_t::implementation_t::add_interface(name_t name, bool linked,
765765

766766
if (initializer_expression.size()) {
767767
cell_set_m.push_back(cell_t(name, linked,
768-
std::bind(&implementation_t::calculate_expression,
769-
std::ref(*this), position1, initializer_expression),
768+
[position1, initializer_expression, this]() {
769+
return calculate_expression(position1, initializer_expression);
770+
},
770771
cell_set_m.size()));
771772
} else {
772773
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,
781782
if (expression.size()) {
782783
// REVISIT (sparent) : Non-transactional on failure.
783784
cell_set_m.push_back(cell_t(access_interface_output, name,
784-
std::bind(&implementation_t::calculate_expression,
785-
std::ref(*this), position2, expression),
785+
[position2, expression, this]() {
786+
return calculate_expression(position2, expression);
787+
},
786788
cell_set_m.size(), &cell_set_m.back()));
787789
} else {
788790
cell_set_m.push_back(cell_t(access_interface_output, name,
789-
std::bind(&implementation_t::get, std::ref(*this), name),
791+
[name, this]() { return get(name); },
790792
cell_set_m.size(), &cell_set_m.back()));
791793
}
792794
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
810812
cell.priority_m = ++priority_high_m;
811813

812814
cell_set_m.push_back(cell_t(access_interface_output, name,
813-
std::bind(&implementation_t::get, std::ref(*this), name),
815+
[name, this]() { return get(name); },
814816
cell_set_m.size(), &cell));
815817

816818
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
852854
const array_t& expression) {
853855
cell_set_m.push_back(cell_t(
854856
access_logic, logic,
855-
std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression),
857+
[position, expression, this]() { return calculate_expression(position, expression); },
856858
cell_set_m.size(), nullptr));
857859

858860
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
868870
// REVISIT (sparent) : Non-transactional on failure.
869871
cell_set_m.push_back(cell_t(
870872
access_invariant, name,
871-
std::bind(&implementation_t::calculate_expression, std::ref(*this), position, expression),
873+
[position, expression, this]() { return calculate_expression(position, expression); },
872874
cell_set_m.size(), nullptr));
873875

874876
output_index_m.insert(cell_set_m.back());
@@ -953,8 +955,10 @@ sheet_t::connection_t sheet_t::implementation_t::monitor_enabled(name_t n, const
953955
monitor(active_m.test(iter->cell_set_pos_m) || (value_accessed_m.test(iter->cell_set_pos_m) &&
954956
(touch_set & priority_accessed_m).any()));
955957

956-
return monitor_enabled_m.connect(std::bind(&sheet_t::implementation_t::enabled_filter, this,
957-
touch_set, iter->cell_set_pos_m, monitor, _1, _2));
958+
return monitor_enabled_m.connect(
959+
[touch_set, iter_pos = iter->cell_set_pos_m, monitor, this](const cell_bits_t& a, const cell_bits_t& b) {
960+
enabled_filter(touch_set, iter_pos, monitor, a, b);
961+
});
958962
}
959963

960964
/**************************************************************************************************/
@@ -1006,8 +1010,7 @@ sheet_t::implementation_t::monitor_contributing(name_t n, const dictionary_t& ma
10061010
monitor(contributing_set(mark, iter->contributing_m));
10071011

10081012
return iter->monitor_contributing_m.connect(
1009-
std::bind(monitor, std::bind(&sheet_t::implementation_t::contributing_set, std::ref(*this),
1010-
mark, _1)));
1013+
[mark, monitor, this](const cell_bits_t& bits) { monitor(contributing_set(mark, bits)); });
10111014
}
10121015

10131016
/**************************************************************************************************/

source/eve_evaluate.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,37 @@ eve_callback_suite_t bind_layout(const bind_layout_proc_t& proc, sheet_t& sheet,
200200
eve_callback_suite_t suite;
201201

202202
suite.add_view_proc_m =
203-
std::bind(proc, _1, _3, std::bind(&evaluate_named_arguments, std::ref(evaluator), _4));
204-
suite.add_cell_proc_m = std::bind(&add_cell, std::ref(sheet), _1, _2, _3, _4);
205-
suite.add_relation_proc_m = std::bind(&add_relation, std::ref(sheet), _1, _2, _3, _4);
203+
[&evaluator, proc](const eve_callback_suite_t::position_t& parent, const line_position_t& /* parse_location */,
204+
name_t name, const array_t& parameters, const std::string& /* brief */,
205+
const std::string& /* detailed */) -> eve_callback_suite_t::position_t {
206+
return proc(parent, name, evaluate_named_arguments(evaluator, parameters));
207+
};
208+
suite.add_cell_proc_m =
209+
[&sheet](adobe::eve_callback_suite_t::cell_type_t type,
210+
adobe::name_t name, const adobe::line_position_t& position,
211+
const adobe::array_t& init_or_expr,
212+
const std::string& /* brief */, const std::string& /* detailed */) -> void {
213+
add_cell(sheet, type, name, position, init_or_expr);
214+
};
215+
suite.add_relation_proc_m =
216+
[&sheet](const adobe::line_position_t& position,
217+
const adobe::array_t& conditional,
218+
const adobe::eve_callback_suite_t::relation_t* first,
219+
const adobe::eve_callback_suite_t::relation_t* last,
220+
const std::string& /* brief */, const std::string& /* detailed */) -> void {
221+
add_relation(sheet, position, conditional, first, last);
222+
};
206223
suite.add_interface_proc_m =
207224
[&sheet](name_t name, bool linked, const line_position_t& position1,
208225
const array_t& initializer, const line_position_t& position2,
209226
const array_t& expression, const std::string& /* brief */,
210227
const std::string& /* detailed */) -> void {
211228
sheet.add_interface(name, linked, position1, initializer, position2, expression);
212229
};
213-
suite.finalize_sheet_proc_m = std::bind(&sheet_t::update, std::ref(sheet));
230+
suite.finalize_sheet_proc_m =
231+
[&sheet]() -> void {
232+
sheet.update();
233+
};
214234

215235
return suite;
216236
}

0 commit comments

Comments
 (0)