From 458dafc812a1bc4f3290397601457e93f53b2dea Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Wed, 17 Jan 2018 19:35:31 -0800 Subject: [PATCH] Add new struct: StringLiteral --- toolsrc/include/vcpkg/base/stringliteral.h | 26 ++++++++++++++++++++++ toolsrc/vcpkglib/vcpkglib.vcxproj | 1 + toolsrc/vcpkglib/vcpkglib.vcxproj.filters | 3 +++ 3 files changed, 30 insertions(+) create mode 100644 toolsrc/include/vcpkg/base/stringliteral.h 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 + +namespace vcpkg +{ + struct StringLiteral + { + template + 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 @@ + 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 @@ Header Files\vcpkg + + Header Files\vcpkg\base + \ No newline at end of file