aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2018-01-17 19:35:31 -0800
committerAlexander Karatarakis <alkarata@microsoft.com>2018-01-17 19:38:17 -0800
commit458dafc812a1bc4f3290397601457e93f53b2dea (patch)
treee71a22d5be9f8e0f75841c00f21c88660ebc82bc
parentc7296cf1f21104b15d9cfe931416245768b484e3 (diff)
downloadvcpkg-458dafc812a1bc4f3290397601457e93f53b2dea.tar.gz
vcpkg-458dafc812a1bc4f3290397601457e93f53b2dea.zip
Add new struct: StringLiteral
-rw-r--r--toolsrc/include/vcpkg/base/stringliteral.h26
-rw-r--r--toolsrc/vcpkglib/vcpkglib.vcxproj1
-rw-r--r--toolsrc/vcpkglib/vcpkglib.vcxproj.filters3
3 files changed, 30 insertions, 0 deletions
diff --git a/toolsrc/include/vcpkg/base/stringliteral.h b/toolsrc/include/vcpkg/base/stringliteral.h
new file mode 100644
index 000000000..c07f04cec
--- /dev/null
+++ b/toolsrc/include/vcpkg/base/stringliteral.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <vcpkg/base/cstringview.h>
+
+namespace vcpkg
+{
+ struct StringLiteral
+ {
+ template<int N>
+ constexpr StringLiteral(const char (&str)[N]) : m_size(N), m_cstr(str)
+ {
+ }
+
+ constexpr const char* c_str() const { return m_cstr; }
+ constexpr size_t size() const { return m_size; }
+
+ operator CStringView() const { return m_cstr; }
+ operator std::string() const { return m_cstr; }
+
+ private:
+ size_t m_size;
+ const char* m_cstr;
+ };
+
+ inline const char* to_printf_arg(const StringLiteral str) { return str.c_str(); }
+}
diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj
index 455891f85..c2bc6b6fd 100644
--- a/toolsrc/vcpkglib/vcpkglib.vcxproj
+++ b/toolsrc/vcpkglib/vcpkglib.vcxproj
@@ -151,6 +151,7 @@
<ClInclude Include="..\include\vcpkg\base\optional.h" />
<ClInclude Include="..\include\vcpkg\base\sortedvector.h" />
<ClInclude Include="..\include\vcpkg\base\span.h" />
+ <ClInclude Include="..\include\vcpkg\base\stringliteral.h" />
<ClInclude Include="..\include\vcpkg\base\strings.h" />
<ClInclude Include="..\include\vcpkg\base\system.h" />
<ClInclude Include="..\include\vcpkg\base\util.h" />
diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
index f8f517ad7..24f943e4a 100644
--- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
+++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
@@ -341,5 +341,8 @@
<ClInclude Include="..\include\vcpkg\userconfig.h">
<Filter>Header Files\vcpkg</Filter>
</ClInclude>
+ <ClInclude Include="..\include\vcpkg\base\stringliteral.h">
+ <Filter>Header Files\vcpkg\base</Filter>
+ </ClInclude>
</ItemGroup>
</Project> \ No newline at end of file