std::is_string_literal
Defined in header <meta> | ||
|---|---|---|
consteval bool is_string_literal( const char* p ); | (1) | (since C++26) |
consteval bool is_string_literal( const wchar_t* p ); | (2) | (since C++26) |
consteval bool is_string_literal( const char8_t* p ); | (3) | (since C++26) |
consteval bool is_string_literal( const char16_t* p ); | (4) | (since C++26) |
consteval bool is_string_literal( const char32_t* p ); | (5) | (since C++26) |
Determines if p points to an element of a string literal object.
The result is determined as follows:
- If
ppoints to an object that is not usable in constant expressions, returnsfalse. - Otherwise, if
ppoints to a subobject of a string literal object, returnstrue. - Otherwise, returns
false.
Parameters
| p | - | a character pointer |
Return value
true if p is statically determined to point into a string literal, false otherwise.
Example
#include <meta>
int main()
{
constexpr const char* p = "";
constexpr const char a[] = "";
static_assert(std::is_string_literal(p));
static_assert(!std::is_string_literal(a));
static_assert(std::is_string_literal(LR"(wcahr_t)"));
static_assert(std::is_string_literal(R"(\N{CAT})"));
}
See also
|
(C++26) | promotes compile-time string to static storage, returning a pointer to the first character of the static string (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/is_string_literal