kernel: use C++11 fold hack to prevent recursion
authorEddie Hung <eddie@fpgeh.com>
Sun, 15 Mar 2020 16:47:20 +0000 (09:47 -0700)
committerEddie Hung <eddie@fpgeh.com>
Thu, 2 Apr 2020 14:14:08 +0000 (07:14 -0700)
kernel/rtlil.h

index c612ea769445566317df05dd0d344adc202f80bd..2d490e6350ee4147bf27b8c048ea93efe0ded09d 100644 (file)
@@ -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<typename T, typename... Args>
-               bool in(T first, Args... rest) const {
-                       return in(first) || in(rest...);
+               template<typename... Args>
+               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<int>{ (result = result || in(args), 0)... };
+            return result;
                }
 
                bool in(IdString rhs) const { return *this == rhs; }