Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions adobe/algorithm/gather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <algorithm> // for std::table_partition
#include <functional>
#include <utility>

#include <boost/range/begin.hpp> // for boost::begin(range)
#include <boost/range/end.hpp> // for boost::end(range)
Expand Down Expand Up @@ -81,8 +82,10 @@ std::pair<Iter, Iter> gather(Iter first, Iter last, Iter pivot, Pred pred) {
return std::make_pair(
std::stable_partition(
first, pivot,
std::bind(std::logical_not<bool>(), std::bind(pred, std::placeholders::_1))),
std::stable_partition(pivot, last, std::bind(pred, std::placeholders::_1)));
[&](const auto& v) -> bool { return !std::invoke(pred, v); }),
std::stable_partition(pivot, last, [&](const auto& v) -> bool {
return std::invoke(pred, v);
}));
}

/**************************************************************************************************/
Expand Down
20 changes: 13 additions & 7 deletions adobe/algorithm/sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ inline void sort(RandomAccessRange& range) {
*/
template <class RandomAccessIterator, class Compare>
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);
});
}

/*!
Expand All @@ -63,7 +65,9 @@ template <typename I, // I models RandomAccessIterator
inline void sort(I f, I l, C c, P p) {
return std::sort(
f, l,
std::bind(c, std::bind(p, std::placeholders::_1), std::bind(p, std::placeholders::_2)));
[&p, &c](const auto& a, const auto& b) {
return std::invoke(c, std::invoke(p, a), std::invoke(p, b));
});
}

/*!
Expand All @@ -76,9 +80,7 @@ template <typename R, // I models RandomAccessRange
typename P>
// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid boost here?

Suggested change
return adobe::sort(boost::begin(r), boost::end(r), c, p);
return adobe::sort(std::begin(r), std::end(r), c, p);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could, but that will come at a price

std::vector<int> vec = ...
std::pair<std::vector<int>::iterator, std::vector<int>::iterator> pair = std::make_pair(vec.begin(), vec.end());
adobe::sort(pair, ...)

this will not work, std::begin()/end doesn't work with pair, and passing pair of iterators is extremely effective. None of it will matter with c++20 and ranges, but before that it's useful

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for that clarification. The changes LGTM - lambdas are much easier to read than bind! I'll defer to @sean-parent to give the final approval.

}

/*!
Expand Down Expand Up @@ -109,7 +111,9 @@ inline void stable_sort(RandomAccessRange& range) {
template <class RandomAccessIterator, class Compare>
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));
[&comp](const auto& a, const auto& b) {
return std::invoke(comp, a, b);
});
}

/*!
Expand Down Expand Up @@ -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));
[&comp](const auto& a, const auto& b) {
return std::invoke(comp, a, b);
});
}

/*!
Expand Down
32 changes: 20 additions & 12 deletions adobe/algorithm/sorted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>

#include <adobe/functional/operator.hpp>

/**************************************************************************************************/

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

f = std::adjacent_find(f, l,
std::bind(std::logical_not<bool>(),
std::bind(o, std::placeholders::_1, std::placeholders::_2)));
f = std::adjacent_find(
f, l,
[&o](const auto& first, const auto& next) {
return !std::invoke(o, first, next);
});

if (f != l)
++f;
return f;
Expand All @@ -63,9 +64,10 @@ template <typename I, // I models InputIterator
// O models StrictWeakOrdering on value_type(I)
inline bool is_sorted(I f, I l, O o) {
return std::adjacent_find(
f, l,
std::bind(std::logical_not<bool>(),
std::bind(o, std::placeholders::_1, std::placeholders::_2))) == l;
f, l,
[&o](const auto& first, const auto& next) {
return !std::invoke(o, first, next);
}) == l;
}

/**************************************************************************************************/
Expand All @@ -88,10 +90,16 @@ template <typename I, // I models ForwardIterator
typename P>
// 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<bool>(),
std::bind(c, std::bind(p, std::placeholders::_1),
std::bind(p, std::placeholders::_2)))) == l;
return std::adjacent_find(
f, l,
[&c, &p](const auto& first, const auto& next) {
return !std::invoke(
c,
std::invoke(p, first),
std::invoke(p, next)
);
}
) == l;
}

/**************************************************************************************************/
Expand Down
12 changes: 4 additions & 8 deletions adobe/arg_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <boost/fusion/include/invoke.hpp>
#include <boost/fusion/include/push_back.hpp>

#include <boost/utility/enable_if.hpp>

#include <adobe/type_inspection.hpp> // ADOBE_HAS_TYPE/ADOBE_HAS_MEMBER
#include <adobe/typeinfo.hpp>

Expand Down Expand Up @@ -111,14 +109,12 @@ struct traits {


namespace detail {
template <class ArgStream,
typename boost::enable_if_c<traits<ArgStream>::has_eof_memberfunction>::type* dummy = nullptr>
template <class ArgStream, std::enable_if_t<traits<ArgStream>::has_eof_memberfunction>* dummy = nullptr>
static bool eof_check(ArgStream& as) {
return as.eof();
}

template <class ArgStream,
typename boost::disable_if_c<traits<ArgStream>::has_eof_memberfunction>::type* dummy = nullptr>
template <class ArgStream, std::enable_if_t<!traits<ArgStream>::has_eof_memberfunction>* dummy = nullptr>
static bool eof_check(ArgStream& as) {
return false;
}
Expand Down Expand Up @@ -453,13 +449,13 @@ struct with_transform {
bool eof() { return detail::eof_check(argstream); }

template <typename R>
R transforming_get(typename boost::enable_if<has_transform<Transformer, R>>::type* dummy = 0) {
R transforming_get(std::enable_if<has_transform<Transformer, R>::value>* dummy = nullptr) {
typedef typename Transformer::template arg_stream_inverse_lookup<R>::type Rfrom;
return transformer.template arg_stream_transform<R>(
arg_stream::get_next_arg<Rfrom>(argstream));
}
template <typename R>
R transforming_get(typename boost::disable_if<has_transform<Transformer, R>>::type* dummy = 0) {
R transforming_get(std::enable_if<!has_transform<Transformer, R>::value>* dummy = nullptr) {
return arg_stream::get_next_arg<R>(argstream);
}

Expand Down
29 changes: 16 additions & 13 deletions source/adam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
[position, expression, this]() { return calculate_expression(position, expression); },
cell_set_m.size(), nullptr));

output_index_m.insert(cell_set_m.back());
Expand All @@ -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),
[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()));
Expand All @@ -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),
[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),
[name, this]() { return get(name); },
cell_set_m.size(), &cell_set_m.back()));
}
output_index_m.insert(cell_set_m.back());
Expand All @@ -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),
[name, this]() { return get(name); },
cell_set_m.size(), &cell));

output_index_m.insert(cell_set_m.back());
Expand Down Expand Up @@ -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),
[position, expression, this]() { return calculate_expression(position, expression); },
cell_set_m.size(), nullptr));

if (!name_index_m.insert(cell_set_m.back()).second) {
Expand All @@ -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),
[position, expression, this]() { return calculate_expression(position, expression); },
cell_set_m.size(), nullptr));

output_index_m.insert(cell_set_m.back());
Expand Down Expand Up @@ -953,8 +955,10 @@ 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));
return monitor_enabled_m.connect(
[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);
});
}

/**************************************************************************************************/
Expand Down Expand Up @@ -1006,8 +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(
std::bind(monitor, std::bind(&sheet_t::implementation_t::contributing_set, std::ref(*this),
mark, _1)));
[mark, monitor, this](const cell_bits_t& bits) { monitor(contributing_set(mark, bits)); });
}

/**************************************************************************************************/
Expand Down
28 changes: 24 additions & 4 deletions source/eve_evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,37 @@ 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,
const array_t& expression, const std::string& /* brief */,
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;
}
Expand Down