24template <
class Container>
25auto keys(
const Container& input_map) -> std::vector<typename Container::key_type>
27 std::vector<typename Container::key_type> retval;
28 retval.reserve(input_map.size());
29 std::transform(std::begin(input_map), std::end(input_map), std::back_inserter(retval),
30 [](
auto&& pair) {
return std::get<0>(std::forward<
decltype(pair)>(pair)); });
45template <
class Container>
46auto values(
const Container& input_map) -> std::vector<typename Container::mapped_type>
48 std::vector<typename Container::mapped_type> retval;
49 retval.reserve(input_map.size());
50 std::transform(std::begin(input_map), std::end(input_map), std::back_inserter(retval),
51 [](
auto&& pair) {
return std::get<1>(std::forward<
decltype(pair)>(pair)); });
67template <
typename F,
typename... FrontArgs>
68constexpr auto bind_front(F&& f, FrontArgs&&... front_args)
71 return [captured_f = std::forward<F>(f), front_args...](
auto&&... back_args) {
72 return std::invoke(captured_f, front_args..., std::forward<
decltype(back_args)>(back_args)...);
94template <
class Container,
class Value>
95constexpr auto contains(
const Container& container,
const Value& value)
noexcept ->
bool
97 return detail::contains(container, value);
112template <
class Container,
class UnaryPredicate>
113constexpr auto contains_if(
const Container& container,
const UnaryPredicate& predicate) ->
bool
115 return std::find_if(std::begin(container), std::end(container), predicate) != std::end(container);
135template <
class Container,
class Value>
136constexpr auto index_of(
const Container& container,
const Value& value)
noexcept
137 -> std::optional<size_t>
139 return detail::index_of(container, value);
154template <
class Container,
class UnaryPredicate>
155constexpr auto index_of_if(
const Container& container,
const UnaryPredicate& predicate)
156 -> std::optional<size_t>
158 const auto it = std::find_if(std::begin(container), std::end(container), predicate);
159 return it != std::end(container) ? std::make_optional(std::distance(std::begin(container), it))
174template <
class T,
class Rep,
class Period>
176 const std::chrono::duration<Rep, Period>& timeout)
noexcept ->
bool
178 return future.wait_for(timeout) == std::future_status::ready;
192template <
class T,
class Clock,
class Duration>
194 const std::chrono::time_point<Clock, Duration>& timeout)
noexcept ->
bool
196 return future.wait_until(timeout) == std::future_status::ready;
Definition algorithm.hpp:12
constexpr auto index_of_if(const Container &container, const UnaryPredicate &predicate) -> std::optional< size_t >
Get the index of the first element in a container for which a predicate is true.
Definition algorithm.hpp:155
constexpr auto contains(const Container &container, const Value &value) noexcept -> bool
Checks whether a container contains a specific value.
Definition algorithm.hpp:95
constexpr auto index_of(const Container &container, const Value &value) noexcept -> std::optional< size_t >
Get the index of the first occurence of a value in a container.
Definition algorithm.hpp:136
constexpr auto bind_front(F &&f, FrontArgs &&... front_args)
Bind arguments to the front of a function.
Definition algorithm.hpp:68
auto values(const Container &input_map) -> std::vector< typename Container::mapped_type >
Get the values of an associative container.
Definition algorithm.hpp:46
auto is_ready_at(const std::future< T > &future, const std::chrono::time_point< Clock, Duration > &timeout) noexcept -> bool
Check whether a future is ready at a specific time.
Definition algorithm.hpp:193
auto keys(const Container &input_map) -> std::vector< typename Container::key_type >
Get the keys of an associative container.
Definition algorithm.hpp:25
constexpr auto contains_if(const Container &container, const UnaryPredicate &predicate) -> bool
Checks if a container contains a value that satisfies a predicate.
Definition algorithm.hpp:113
auto is_ready_after(const std::future< T > &future, const std::chrono::duration< Rep, Period > &timeout) noexcept -> bool
Check whether a future is ready after a timeout.
Definition algorithm.hpp:175