Skip to content

Commit 1cb8afb

Browse files
[Testing] Use is_detected for StringMapEntry ostream check (NFC) (#159954)
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.
1 parent b5c6588 commit 1cb8afb

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

llvm/include/llvm/Testing/ADT/StringMapEntry.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_TESTING_ADT_STRINGMAPENTRY_H_
1010
#define LLVM_TESTING_ADT_STRINGMAPENTRY_H_
1111

12+
#include "llvm/ADT/STLForwardCompat.h"
1213
#include "llvm/ADT/StringMapEntry.h"
1314
#include "gmock/gmock.h"
1415
#include <ostream>
@@ -17,13 +18,9 @@
1718
namespace llvm {
1819
namespace detail {
1920

20-
template <typename T, typename = std::void_t<>>
21-
struct CanOutputToOStream : std::false_type {};
22-
2321
template <typename T>
24-
struct CanOutputToOStream<T, std::void_t<decltype(std::declval<std::ostream &>()
25-
<< std::declval<T>())>>
26-
: std::true_type {};
22+
using check_ostream =
23+
decltype(std::declval<std::ostream &>() << std::declval<T>());
2724

2825
} // namespace detail
2926

@@ -32,7 +29,8 @@ struct CanOutputToOStream<T, std::void_t<decltype(std::declval<std::ostream &>()
3229
template <typename T>
3330
std::ostream &operator<<(std::ostream &OS, const StringMapEntry<T> &E) {
3431
OS << "{\"" << E.getKey().data() << "\": ";
35-
if constexpr (detail::CanOutputToOStream<decltype(E.getValue())>::value) {
32+
if constexpr (is_detected<detail::check_ostream,
33+
decltype(E.getValue())>::value) {
3634
OS << E.getValue();
3735
} else {
3836
OS << "non-printable value";

0 commit comments

Comments
 (0)