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);