[libc++] Introduce __debug_db_insert_c()

There are a lot of
```
#if _LIBCPP_DEBUG_LEVEL == 2
    __get_db()->__insert_c(this);
#endif
```

This patch introduces `__debug_db_insert_c()` to put the `#if` in one central place.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116947

NOKEYCHECK=True
GitOrigin-RevId: e3cf70502cae1b29ece72a0d6ef28352ca2319fa
diff --git a/include/__debug b/include/__debug
index 42f6cef..4e80474 100644
--- a/include/__debug
+++ b/include/__debug
@@ -12,6 +12,7 @@
 
 #include <__config>
 #include <iosfwd>
+#include <type_traits>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -268,6 +269,16 @@
 
 #endif // _LIBCPP_DEBUG_LEVEL == 2 || defined(_LIBCPP_BUILDING_LIBRARY)
 
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_insert_c(_Tp* __c) {
+#if _LIBCPP_DEBUG_LEVEL == 2
+    if (!__libcpp_is_constant_evaluated())
+        __get_db()->__insert_c(__c);
+#else
+    (void)(__c);
+#endif
+}
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP_DEBUG_H