From e061f7326feb0b71d519de46883b66195affaa11 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 20 Mar 2017 19:13:12 -0700 Subject: [PATCH] ircd::util: Follow up for_each() with tuple until(). --- include/ircd/util.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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