base: Modernize metaprogramming in ScopedGeneric for C++20.

Bug: 1501952
Change-Id: I594924c1beec5d07b599c19ef205924521ed0b2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029066
Auto-Submit: Jeremy Roman <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1225018}
diff --git a/base/scoped_generic.h b/base/scoped_generic.h
index 4b034a1..31dd559 100644
--- a/base/scoped_generic.h
+++ b/base/scoped_generic.h
@@ -7,6 +7,7 @@
 
 #include <stdlib.h>
 
+#include <concepts>
 #include <type_traits>
 
 #include "base/check.h"
@@ -260,38 +261,22 @@
     }
   }
 
-  template <typename Void = void>
-  typename std::enable_if_t<
-      std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
-      Void>
-  TrackAcquire(const T& value) {
-    if (value != traits_type::InvalidValue()) {
-      data_.Acquire(static_cast<const ScopedGeneric&>(*this), value);
+  void TrackAcquire(const T& value) {
+    if constexpr (std::derived_from<Traits, ScopedGenericOwnershipTracking>) {
+      if (value != traits_type::InvalidValue()) {
+        data_.Acquire(static_cast<const ScopedGeneric&>(*this), value);
+      }
     }
   }
 
-  template <typename Void = void>
-  typename std::enable_if_t<
-      !std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
-      Void>
-  TrackAcquire(const T& value) {}
-
-  template <typename Void = void>
-  typename std::enable_if_t<
-      std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
-      Void>
-  TrackRelease(const T& value) {
-    if (value != traits_type::InvalidValue()) {
-      data_.Release(static_cast<const ScopedGeneric&>(*this), value);
+  void TrackRelease(const T& value) {
+    if constexpr (std::derived_from<Traits, ScopedGenericOwnershipTracking>) {
+      if (value != traits_type::InvalidValue()) {
+        data_.Release(static_cast<const ScopedGeneric&>(*this), value);
+      }
     }
   }
 
-  template <typename Void = void>
-  typename std::enable_if_t<
-      !std::is_base_of_v<ScopedGenericOwnershipTracking, Traits>,
-      Void>
-  TrackRelease(const T& value) {}
-
   // Forbid comparison. If U != T, it totally doesn't make sense, and if U ==
   // T, it still doesn't make sense because you should never have the same
   // object owned by two different ScopedGenerics.