[libc++] Granularize <type_traits> includes in <compare>

Reviewed By: Mordante, #libc

Spies: libcxx-commits

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

NOKEYCHECK=True
GitOrigin-RevId: e0a66116fcccd59d12485810f5311efafa134ea5
diff --git a/include/exception b/include/exception
index 98b355f..e0f4268 100644
--- a/include/exception
+++ b/include/exception
@@ -80,9 +80,15 @@
 #include <__availability>
 #include <__config>
 #include <__memory/addressof.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/is_base_of.h>
+#include <__type_traits/is_class.h>
+#include <__type_traits/is_convertible.h>
+#include <__type_traits/is_copy_constructible.h>
+#include <__type_traits/is_final.h>
+#include <__type_traits/is_polymorphic.h>
 #include <cstddef>
 #include <cstdlib>
-#include <type_traits>
 #include <version>
 
 // <vcruntime_exception.h> defines its own std::exception and std::bad_exception types,
@@ -371,4 +377,8 @@
 
 } // namespace std
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
+#  include <type_traits>
+#endif
+
 #endif // _LIBCPP_EXCEPTION