summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Kolb <craig.kolb@gmail.com>2022-05-31 12:04:08 -0700
committerGitHub <noreply@github.com>2022-05-31 15:04:08 -0400
commit393ce4f746c6697442a3a61debd12101fbe4e9db (patch)
tree1364d5741490384d23e4aed0b28c013efe0ad51f
parent1a83d50a5d9e85934386310c17a14860cc92e75c (diff)
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 <jsmall@nvidia.com>
-rw-r--r--source/core/slang-string.cpp5
-rw-r--r--source/core/slang-string.h4
2 files changed, 9 insertions, 0 deletions
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 <string.h>
#include <cstdlib>
#include <stdio.h>
+#include <iostream>
#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