From 393ce4f746c6697442a3a61debd12101fbe4e9db Mon Sep 17 00:00:00 2001 From: Craig Kolb Date: Tue, 31 May 2022 12:04:08 -0700 Subject: Add Slang::String compatibility with std::ostream (#2256) * Work around MacOS compilation issue with embed stlib - The enable-stdlib-generator project is created with 'kind = StaticLib' to allow the build to work, even though the project doesn't actually create a library. - Unlike some other platforms, MacOs "ar" emits an error if no object files are listed to be added to an archive. This causes enable-stdlib-generator to fail on MacOS. - Changing the project's kind to "SharedLib" works around the issue. Other values for kind do not seem to work around the issue. - Add an optional flag to generatorProject to indicate that kind = "SharedLibrary" should be used, rather than "StaticLibrary" - Enable embed stdlib in github_macos_build.sh * Allow Strings to be used with std::ostream. Co-authored-by: jsmall-nvidia --- source/core/slang-string.cpp | 5 +++++ source/core/slang-string.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index 1a6221cc8..5f2ba13ba 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -690,5 +690,10 @@ namespace Slang return true; } +} +std::ostream& operator<< (std::ostream& stream, const Slang::String& s) +{ + stream << s.getBuffer(); + return stream; } diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 5119dac8f..e8ee76397 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "slang-smart-pointer.h" #include "slang-common.h" @@ -1038,6 +1039,7 @@ namespace Slang length -= actualDelLength; } #endif + friend std::ostream& operator<< (std::ostream& stream, const String& s); void Clear() { @@ -1051,4 +1053,6 @@ namespace Slang float StringToFloat(const String & str); } +std::ostream& operator<< (std::ostream& stream, const Slang::String& s); + #endif -- cgit v1.2.3