diff --git a/include/ircd/util.h b/include/ircd/util.h index 3d1c6fcfd..37ea25e7a 100644 --- a/include/ircd/util.h +++ b/include/ircd/util.h @@ -145,6 +145,31 @@ for_each(const std::tuple &t, } +// +// Iteration of a tuple until() style: your closure returns true to continue, false +// to break. until() then remains true to the end, or returns false if not. + +template +typename std::enable_if>::value, bool>::type +until(const std::tuple &t, + func&& f) +{ + return true; +} + +template +typename std::enable_if>::value, bool>::type +until(const std::tuple &t, + func&& f) +{ + return f(std::get(t))? until(t, std::forward(f)) : false; +} + + // For conforming enums include a _NUM_ as the last element, // then num_of() works template