algo/search: improve minimises
documentation
This commit is contained in:
parent
e42f71f9af
commit
0138b00f87
@ -9,6 +9,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../types/traits.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
|
||||
|
||||
@ -23,10 +26,30 @@ namespace cruft::search {
|
||||
/// The provided function will be invoked with the supplied argument pack
|
||||
/// as the first arguments and the dereferenced iterator as the final
|
||||
/// argument.
|
||||
template <typename InputT, typename FunctionT, typename ...Args>
|
||||
InputT
|
||||
minimises (InputT first, InputT last, FunctionT &&func, Args &&...args)
|
||||
{
|
||||
///
|
||||
/// \tparam ForwardT A forward iterator
|
||||
/// \tparam FunctionT An invokable
|
||||
/// \param first The first iterator in the range to be searched
|
||||
/// \param last The last iterator in the range to be searched
|
||||
/// \param func A functional which returns a comparable value
|
||||
/// \param args The first arguments passed to `func`
|
||||
/// \return A pair of the best score, and the best iterator
|
||||
template <
|
||||
typename ForwardT,
|
||||
typename FunctionT,
|
||||
typename ...Args
|
||||
>
|
||||
auto
|
||||
minimises (
|
||||
ForwardT first,
|
||||
ForwardT last,
|
||||
FunctionT &&func,
|
||||
Args &&...args
|
||||
) {
|
||||
using value_type = typename std::iterator_traits<ForwardT>::value_type;
|
||||
using score_t = std::invoke_result_t<FunctionT, Args..., value_type>;
|
||||
static_assert (::cruft::is_orderable_v<score_t>);
|
||||
|
||||
auto best_score = std::invoke (func, args..., *first);
|
||||
auto best_item = first;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user