Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

This patch replaces a std::void_t-based detection of the streaming
(<<) operator with a llvm::is_detected-based detection. This way, we
don't have to roll our own SFINAE logic and fallback mechanism.

This patch replaces a std::void_t-based detection of the streaming
(<<) operator with a llvm::is_detected-based detection.  This way, we
don't have to roll our own SFINAE logic and fallback mechanism.
@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

This patch replaces a std::void_t-based detection of the streaming
(<<) operator with a llvm::is_detected-based detection. This way, we
don't have to roll our own SFINAE logic and fallback mechanism.


Full diff: https://github.com/llvm/llvm-project/pull/159954.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Testing/ADT/StringMapEntry.h (+5-7)
diff --git a/llvm/include/llvm/Testing/ADT/StringMapEntry.h b/llvm/include/llvm/Testing/ADT/StringMapEntry.h
index 7649c30078181..5fba1dd914d86 100644
--- a/llvm/include/llvm/Testing/ADT/StringMapEntry.h
+++ b/llvm/include/llvm/Testing/ADT/StringMapEntry.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_TESTING_ADT_STRINGMAPENTRY_H_
 #define LLVM_TESTING_ADT_STRINGMAPENTRY_H_
 
+#include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/StringMapEntry.h"
 #include "gmock/gmock.h"
 #include <ostream>
@@ -17,13 +18,9 @@
 namespace llvm {
 namespace detail {
 
-template <typename T, typename = std::void_t<>>
-struct CanOutputToOStream : std::false_type {};
-
 template <typename T>
-struct CanOutputToOStream<T, std::void_t<decltype(std::declval<std::ostream &>()
-                                                  << std::declval<T>())>>
-    : std::true_type {};
+using check_ostream =
+    decltype(std::declval<std::ostream &>() << std::declval<T>());
 
 } // namespace detail
 
@@ -32,7 +29,8 @@ struct CanOutputToOStream<T, std::void_t<decltype(std::declval<std::ostream &>()
 template <typename T>
 std::ostream &operator<<(std::ostream &OS, const StringMapEntry<T> &E) {
   OS << "{\"" << E.getKey().data() << "\": ";
-  if constexpr (detail::CanOutputToOStream<decltype(E.getValue())>::value) {
+  if constexpr (is_detected<detail::check_ostream,
+                            decltype(E.getValue())>::value) {
     OS << E.getValue();
   } else {
     OS << "non-printable value";

@kazutakahirata kazutakahirata merged commit 1cb8afb into llvm:main Sep 21, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250920_10TMP_StringMapEntry_is_detected branch September 21, 2025 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants