summaryrefslogtreecommitdiffstats
path: root/Source/cmString.hxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-12-08 02:08:17 (GMT)
committerBrad King <brad.king@kitware.com>2018-12-12 13:10:15 (GMT)
commita0841b59bdacc1e550e6607d9e44e79ae456cd19 (patch)
tree780f579afba03f7feb663889582889438d775e0a /Source/cmString.hxx
parent9d5fe8e96a074b6e112d981302c77e31a1bcde00 (diff)
downloadCMake-a0841b59bdacc1e550e6607d9e44e79ae456cd19.zip
CMake-a0841b59bdacc1e550e6607d9e44e79ae456cd19.tar.gz
CMake-a0841b59bdacc1e550e6607d9e44e79ae456cd19.tar.bz2
String: Add support for a ""_s string literal syntax
Create a `static_string_view` type that binds only to the static storage of string literals. Teach `cm::String` to borrow from these implicitly.
Diffstat (limited to 'Source/cmString.hxx')
-rw-r--r--Source/cmString.hxx15
1 files changed, 14 insertions, 1 deletions
diff --git a/Source/cmString.hxx b/Source/cmString.hxx
index 3b59353..52e891c 100644
--- a/Source/cmString.hxx
+++ b/Source/cmString.hxx
@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cm_static_string_view.hxx"
#include "cm_string_view.hxx"
#include <algorithm>
@@ -90,6 +91,12 @@ struct IntoString<string_view> : std::true_type
};
template <>
+struct IntoString<static_string_view> : std::true_type
+{
+ static string_view into_string(static_string_view s) { return s; }
+};
+
+template <>
struct IntoString<char> : std::true_type
{
static std::string into_string(char const& c) { return std::string(1, c); }
@@ -157,6 +164,12 @@ struct AsStringView<string_view> : std::true_type
};
template <>
+struct AsStringView<static_string_view> : std::true_type
+{
+ static string_view view(static_string_view const& s) { return s; }
+};
+
+template <>
struct AsStringView<String> : std::true_type
{
static string_view view(String const& s);
@@ -370,7 +383,7 @@ public:
}
/** Assign to an empty string. */
- void clear() { *this = String(string_view("", 0), Private()); }
+ void clear() { *this = ""_s; }
/** Insert 'count' copies of 'ch' at position 'index'. */
String& insert(size_type index, size_type count, char ch);