From 71974913643ecb2a7cabc9b5e356b3069bdd49e8 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 23 Aug 2017 14:58:21 -0600 Subject: [PATCH] ircd::util: Add constexpr kronecker delta. --- include/ircd/util.h | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/include/ircd/util.h b/include/ircd/util.h index 11cb3aaac..1aabc1030 100644 --- a/include/ircd/util.h +++ b/include/ircd/util.h @@ -377,6 +377,60 @@ runtil(std::tuple &t, return runtil(t, std::forward(f)); } +// +// Kronecker delta +// + +template +constexpr +typename std::enable_if::type +kronecker_delta(const std::tuple &t, + func&& f) +{ + using value_type = typename std::tuple_element>::type; + f(static_cast(std::get(t))); +} + +template +constexpr +typename std::enable_if::type +kronecker_delta(std::tuple &t, + func&& f) +{ + using value_type = typename std::tuple_element>::type; + f(static_cast(std::get(t))); +} + +template +constexpr +typename std::enable_if<(i < j), void>::type +kronecker_delta(const std::tuple &t, + func&& f) +{ + kronecker_delta(t, std::forward(f)); +} + +template +constexpr +typename std::enable_if<(i < j), void>::type +kronecker_delta(std::tuple &t, + func&& f) +{ + kronecker_delta(t, std::forward(f)); +} + // For conforming enums include a _NUM_ as the last element, // then num_of() works