[llvm] [libc] Add is_member_pointer_v (PR #65631)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 09:12:18 PDT 2023


https://github.com/gchatelet created https://github.com/llvm/llvm-project/pull/65631:

Implementation from https://en.cppreference.com/w/cpp/types/is_member_pointer

>From 95b9eb358c9a73e0ea05e8bcc6eb240977b6d242 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Thu, 7 Sep 2023 16:05:38 +0000
Subject: [PATCH] [libc] Add is_member_pointer_v

---
 libc/src/__support/CPP/type_traits.h          |  1 +
 .../CPP/type_traits/is_member_pointer.h       | 30 +++++++++++++++++++
 .../llvm-project-overlay/libc/BUILD.bazel     |  1 +
 3 files changed, 32 insertions(+)
 create mode 100644 libc/src/__support/CPP/type_traits/is_member_pointer.h

diff --git a/libc/src/__support/CPP/type_traits.h b/libc/src/__support/CPP/type_traits.h
index 7794b39e0d8f4c3..8c351c13b954b46 100644
--- a/libc/src/__support/CPP/type_traits.h
+++ b/libc/src/__support/CPP/type_traits.h
@@ -30,6 +30,7 @@
 #include "src/__support/CPP/type_traits/is_function.h"
 #include "src/__support/CPP/type_traits/is_integral.h"
 #include "src/__support/CPP/type_traits/is_lvalue_reference.h"
+#include "src/__support/CPP/type_traits/is_member_pointer.h"
 #include "src/__support/CPP/type_traits/is_null_pointer.h"
 #include "src/__support/CPP/type_traits/is_pointer.h"
 #include "src/__support/CPP/type_traits/is_reference.h"
diff --git a/libc/src/__support/CPP/type_traits/is_member_pointer.h b/libc/src/__support/CPP/type_traits/is_member_pointer.h
new file mode 100644
index 000000000000000..5b273d5dc7bde17
--- /dev/null
+++ b/libc/src/__support/CPP/type_traits/is_member_pointer.h
@@ -0,0 +1,30 @@
+//===-- is_member_pointer type_traits ---------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H
+
+#include "src/__support/CPP/type_traits/false_type.h"
+#include "src/__support/CPP/type_traits/remove_cv.h"
+#include "src/__support/CPP/type_traits/true_type.h"
+#include "src/__support/macros/attributes.h"
+
+namespace __llvm_libc::cpp {
+
+// is_member_pointer
+template <class T> struct is_member_pointer_helper : cpp::false_type {};
+template <class T, class U>
+struct is_member_pointer_helper<T U::*> : cpp::true_type {};
+template <class T>
+struct is_member_pointer : is_member_pointer_helper<cpp::remove_cv_t<T>> {};
+template <class T>
+LIBC_INLINE_VAR constexpr bool is_member_pointer_v =
+    is_member_pointer<T>::value;
+
+} // namespace __llvm_libc::cpp
+
+#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_MEMBER_POINTER_H
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 0f35d3df4c49a1c..360672d682095d5 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -307,6 +307,7 @@ libc_support_library(
         "src/__support/CPP/type_traits/is_function.h",
         "src/__support/CPP/type_traits/is_integral.h",
         "src/__support/CPP/type_traits/is_lvalue_reference.h",
+        "src/__support/CPP/type_traits/is_member_pointer.h",
         "src/__support/CPP/type_traits/is_null_pointer.h",
         "src/__support/CPP/type_traits/is_pointer.h",
         "src/__support/CPP/type_traits/is_reference.h",



More information about the llvm-commits mailing list