mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
44
base/control_flow.hpp
Normal file
44
base/control_flow.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace base
|
||||
{
|
||||
// This enum is used to control the flow of ForEach invocations.
|
||||
enum class ControlFlow
|
||||
{
|
||||
Break,
|
||||
Continue
|
||||
};
|
||||
|
||||
// A wrapper that calls |fn| with arguments |args|.
|
||||
// To avoid excessive calls, |fn| may signal the end of execution via its return value,
|
||||
// which should then be checked by the wrapper's user.
|
||||
template <typename Fn>
|
||||
class ControlFlowWrapper
|
||||
{
|
||||
public:
|
||||
template <typename Gn>
|
||||
explicit ControlFlowWrapper(Gn && gn) : m_fn(std::forward<Gn>(gn))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
std::enable_if_t<std::is_same_v<std::invoke_result_t<Fn, Args...>, ControlFlow>, ControlFlow>
|
||||
operator()(Args &&... args)
|
||||
{
|
||||
return m_fn(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
std::enable_if_t<std::is_same_v<std::invoke_result_t<Fn, Args...>, void>, ControlFlow>
|
||||
operator()(Args &&... args)
|
||||
{
|
||||
m_fn(std::forward<Args>(args)...);
|
||||
return ControlFlow::Continue;
|
||||
}
|
||||
|
||||
private:
|
||||
Fn m_fn;
|
||||
};
|
||||
} // namespace base
|
||||
Reference in New Issue
Block a user