mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-08 02:36:49 +08:00
Move to new count_if algorithm at dispatch
This commit is contained in:
parent
ba492308f4
commit
6fe39816cf
@ -842,6 +842,23 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
template<typename Itr1, typename Itr2, typename BinaryPredicate>
|
||||||
|
typename std::iterator_traits<Itr1>::difference_type
|
||||||
|
count_if(Itr1 first1, const Itr1 &last1, Itr2 first2, BinaryPredicate p)
|
||||||
|
{
|
||||||
|
typename std::iterator_traits<Itr1>::difference_type count = 0;
|
||||||
|
|
||||||
|
while (first1 != last1)
|
||||||
|
{
|
||||||
|
if (p(*first1, *first2)) ++count;
|
||||||
|
++first1; ++first2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take a vector of functions and a vector of parameters. Attempt to execute
|
* Take a vector of functions and a vector of parameters. Attempt to execute
|
||||||
* each function against the set of parameters, in order, until a matching
|
* each function against the set of parameters, in order, until a matching
|
||||||
@ -863,14 +880,12 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
ordered_funcs.emplace_back(plist.size(), func.get());
|
ordered_funcs.emplace_back(plist.size(), func.get());
|
||||||
} else if (arity == static_cast<int>(plist.size())) {
|
} else if (arity == static_cast<int>(plist.size())) {
|
||||||
size_t numdiffs = 0;
|
const auto numdiffs = detail::count_if(
|
||||||
for (size_t i = 0; i < plist.size(); ++i)
|
plist.begin(), plist.end(), func->get_param_types().begin() + 1,
|
||||||
{
|
[](const Boxed_Value &bv, const Type_Info &ti) {
|
||||||
if (!func->get_param_types()[i+1].bare_equal(plist[i].get_type_info()))
|
return !ti.bare_equal(bv.get_type_info());
|
||||||
{
|
}
|
||||||
++numdiffs;
|
);
|
||||||
}
|
|
||||||
}
|
|
||||||
ordered_funcs.emplace_back(numdiffs, func.get());
|
ordered_funcs.emplace_back(numdiffs, func.get());
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
@ -878,11 +893,12 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::stable_sort(ordered_funcs.begin(), ordered_funcs.end(),
|
std::stable_sort(ordered_funcs.begin(), ordered_funcs.end(),
|
||||||
[](const decltype(ordered_funcs)::const_reference &t_lhs, const decltype(ordered_funcs)::const_reference &t_rhs)
|
[](decltype(ordered_funcs)::const_reference t_lhs, decltype(ordered_funcs)::const_reference t_rhs)
|
||||||
{
|
{
|
||||||
return t_lhs.first < t_rhs.first;
|
return t_lhs.first < t_rhs.first;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
for (const auto &func : ordered_funcs )
|
for (const auto &func : ordered_funcs )
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user