From: Eddie Hung Date: Sun, 15 Mar 2020 16:47:20 +0000 (-0700) Subject: kernel: use C++11 fold hack to prevent recursion X-Git-Tag: working-ls180~697^2~3 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7bcbf0c9d1327c1e2fb3b96aa2cd888afbeb11b1;p=yosys.git kernel: use C++11 fold hack to prevent recursion --- diff --git a/kernel/rtlil.h b/kernel/rtlil.h index c612ea769..2d490e635 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -361,9 +361,14 @@ namespace RTLIL // often one needs to check if a given IdString is part of a list (for example a list // of cell types). the following functions helps with that. - template - bool in(T first, Args... rest) const { - return in(first) || in(rest...); + template + bool in(Args... args) const { + //return in(first) || in(rest...); + + // Credit: https://articles.emptycrate.com/2016/05/14/folds_in_cpp11_ish.html + bool result = false; + (void) std::initializer_list{ (result = result || in(args), 0)... }; + return result; } bool in(IdString rhs) const { return *this == rhs; }