| 934 | /// function is found or throw dispatch_error if no matching function is found |
| 935 | template<typename Funcs> |
| 936 | Boxed_Value dispatch(const Funcs &funcs, |
| 937 | const std::vector<Boxed_Value> &plist, const Type_Conversions_State &t_conversions) |
| 938 | { |
| 939 | std::vector<std::pair<size_t, const Proxy_Function_Base *>> ordered_funcs; |
| 940 | ordered_funcs.reserve(funcs.size()); |
| 941 | |
| 942 | for (const auto &func : funcs) |
| 943 | { |
| 944 | const auto arity = func->get_arity(); |
| 945 | |
| 946 | if (arity == -1) |
| 947 | { |
| 948 | ordered_funcs.emplace_back(plist.size(), func.get()); |
| 949 | } else if (arity == static_cast<int>(plist.size())) { |
| 950 | size_t numdiffs = 0; |
| 951 | for (size_t i = 0; i < plist.size(); ++i) |
| 952 | { |
| 953 | if (!func->get_param_types()[i+1].bare_equal(plist[i].get_type_info())) |
| 954 | { |
| 955 | ++numdiffs; |
| 956 | } |
| 957 | } |
| 958 | ordered_funcs.emplace_back(numdiffs, func.get()); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | |
| 963 | for (size_t i = 0; i <= plist.size(); ++i) |
| 964 | { |
| 965 | for (const auto &func : ordered_funcs ) |
| 966 | { |
| 967 | try { |
| 968 | if (func.first == i && (i == 0 || func.second->filter(plist, t_conversions))) |
| 969 | { |
| 970 | return (*(func.second))(plist, t_conversions); |
| 971 | } |
| 972 | } catch (const exception::bad_boxed_cast &) { |
| 973 | //parameter failed to cast, try again |
| 974 | } catch (const exception::arity_error &) { |
| 975 | //invalid num params, try again |
| 976 | } catch (const exception::guard_error &) { |
| 977 | //guard failed to allow the function to execute, |
| 978 | //try again |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | return detail::dispatch_with_conversions(ordered_funcs.cbegin(), ordered_funcs.cend(), plist, t_conversions, funcs); |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 |
no test coverage detected