From 472815d3c11ea9e5a6385def9865649498a30248 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Sat, 4 Mar 2023 00:15:24 +0000 Subject: [PATCH] tint: Fix build on windows + cmake Change-Id: Id24e6c27a00700123e1677585ff7759c0bbcfe07 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122523 Commit-Queue: Ben Clayton Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Dan Sinclair --- src/tint/utils/string_stream.h | 48 +++++++++------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/src/tint/utils/string_stream.h b/src/tint/utils/string_stream.h index 4703095081..77e8fe100a 100644 --- a/src/tint/utils/string_stream.h +++ b/src/tint/utils/string_stream.h @@ -30,6 +30,16 @@ namespace tint::utils { /// Stringstream wrapper which automatically resets the locale and sets floating point emission /// settings needed for Tint. class StringStream { + using SetWRetTy = decltype(std::setw(std::declval())); + using SetPrecisionRetTy = decltype(std::setprecision(std::declval())); + using SetFillRetTy = decltype(std::setfill(std::declval())); + + /// Evaluates to true if `T` is the return type of std::setw, std:setprecision or std::setfill. + template + static constexpr bool IsSetType = std::is_same_v> || + std::is_same_v> || + std::is_same_v>; + public: /// Constructor StringStream(); @@ -149,12 +159,9 @@ class StringStream { return *this; } - /// The callback to emit a `std::hex` to the stream - using StdHex = std::ios_base& (*)(std::ios_base&); - /// @param manipulator the callback to emit too /// @returns a reference to this - StringStream& operator<<(StdHex manipulator) { + StringStream& operator<<(decltype(std::hex) manipulator) { // call the function, and return it's value manipulator(sstream_); return *this; @@ -162,38 +169,7 @@ class StringStream { /// @param value the value to emit /// @returns a reference to this - template ())), - typename std::decay::type>::value, - int>::type = 0> - StringStream& operator<<(T&& value) { - // call the function, and return it's value - sstream_ << std::forward(value); - return *this; - } - - // On MSVC the type of `std::setw` and `std::setprecision` are the same. Can't check for - // _MSC_VER because this is also set by clang-cl on windows. -#if defined(__GNUC__) || defined(__clang__) - /// @param value the value to emit - /// @returns a reference to this - template ())), - typename std::decay::type>::value, - int>::type = 0> - StringStream& operator<<(T&& value) { - // call the function, and return it's value - sstream_ << std::forward(value); - return *this; - } -#endif // defined(_MSC_VER) - - /// @param value the value to emit - /// @returns a reference to this - template ())), - typename std::decay::type>::value, - char>::type = 0> + template , int> = 0> StringStream& operator<<(T&& value) { // call the function, and return it's value sstream_ << std::forward(value);