From 368d328496a6764856f3b3b9d2ec941d2d54545f Mon Sep 17 00:00:00 2001
From: Alexander Peyser <apeyser@users.noreply.github.com>
Date: Fri, 9 Dec 2016 11:04:03 +0100
Subject: [PATCH] Add initializer_list version for is_in in modccutil.hpp
 (#122)

Fix `is_in` compilation error with initializer lists and clang 3.7.1.

Addresses part of issue #121: `template <typename T, int N> bool is_in(T thing, const T (&list)[N])` fails to match against an initializer list second argument with clang-3.7.1 in `modcc/cprinter.cpp`.

* Add overload `template <typename T> bool is_in(T thing, const std::initializer_list<T> list) ` for `is_in` in `modccutil.hpp`. Fixes clang issue and verified to work with a version of gcc as well.
---
 modcc/modccutil.hpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/modcc/modccutil.hpp b/modcc/modccutil.hpp
index 80c90d9f..fde6828c 100644
--- a/modcc/modccutil.hpp
+++ b/modcc/modccutil.hpp
@@ -4,6 +4,7 @@
 #include <memory>
 #include <sstream>
 #include <vector>
+#include <initializer_list>
 
 // is thing in list?
 template <typename T, int N>
@@ -16,6 +17,16 @@ bool is_in(T thing, const T (&list)[N]) {
     return false;
 }
 
+template <typename T>
+bool is_in(T thing, const std::initializer_list<T> list) {
+    for(auto const& item : list) {
+        if(thing==item) {
+            return true;
+        }
+    }
+    return false;
+}
+
 inline std::string pprintf(const char *s) {
     std::string errstring;
     while(*s) {
-- 
GitLab