Namespaces
Variants

std::is_string_literal

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Reflection queries
Reflection layout queries
Type properties
Type property queries
 
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 p points to an object that is not usable in constant expressions, returns false.
  • Otherwise, if p points to a subobject of a string literal object, returns true.
  • 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

promotes compile-time string to static storage, returning a pointer to the first character of the static string
(function template) [edit]