mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-28 13:49:39 +08:00
Add new struct: StringLiteral
This commit is contained in:
parent
c7296cf1f2
commit
458dafc812
26
toolsrc/include/vcpkg/base/stringliteral.h
Normal file
26
toolsrc/include/vcpkg/base/stringliteral.h
Normal file
@ -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(); }
|
||||
}
|
@ -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" />
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user