clang_wrap.h: extract ISL_VALID_EXPR_FOR_TEMPLATE_ARG macro from HasGetFileRef
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Sun, 16 Nov 2025 15:06:30 +0000 (16 16:06 +0100)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Sat, 22 Nov 2025 14:26:18 +0000 (22 15:26 +0100)
The macro will be reused in the next commit.

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
interface/include/isl-interface/clang_wrap.h

index 351d23b..7c214e2 100644 (file)
@@ -244,24 +244,30 @@ static const FileEntry *ignore_error(const T obj)
        return ignore_error_helper(obj, 0, NULL);
 }
 
-/* A template class with value true if "T" has a getFileRef method.
+/* Define a template class "CLASS" with value true
+ * if "EXPR" is valid for its template argument (available as "U" in "EXPR").
  */
-template <typename T>
-struct HasGetFileRef {
-private:
-    template <typename U>
-    static auto test(int) ->
-       decltype(std::declval<U>().
-           getFileRef(std::declval<const std::string &>()), std::true_type());
-
-    template <typename>
-    static std::false_type test(...);
-
-public:
-    using type = decltype(test<T>(0));
-    static constexpr bool value = type::value;
+#define ISL_VALID_EXPR_FOR_TEMPLATE_ARG(CLASS, EXPR)                   \
+template <typename T>                                                  \
+struct CLASS {                                                         \
+private:                                                               \
+    template <typename U>                                              \
+    static auto test(int) -> decltype(EXPR, std::true_type());         \
+                                                                       \
+    template <typename>                                                        \
+    static std::false_type test(...);                                  \
+                                                                       \
+public:                                                                        \
+    using type = decltype(test<T>(0));                                 \
+    static constexpr bool value = type::value;                         \
 };
 
+/* A template class with value true if the template argument
+ * has a getFileRef method.
+ */
+ISL_VALID_EXPR_FOR_TEMPLATE_ARG(HasGetFileRef,
+       std::declval<U>().getFileRef(std::declval<const std::string &>()))
+
 /* Return a wrapper around the FileEntryRef/FileEntry
  * corresponding to the given file name.  The wrapper evaluates
  * to false if an error occurs.