#pragma once #include #include 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 class ControlFlowWrapper { public: template explicit ControlFlowWrapper(Gn && gn) : m_fn(std::forward(gn)) { } template std::enable_if_t, base::ControlFlow>::value, base::ControlFlow> operator()(Args &&... args) { return m_fn(std::forward(args)...); } template std::enable_if_t, void>::value, base::ControlFlow> operator()(Args &&... args) { m_fn(std::forward(args)...); return ControlFlow::Continue; } private: Fn m_fn; }; } // namespace base