std::literals::string_view_literals::operator""sv
From cppreference.com
Defined in header <string_view>
|
||
constexpr string_view operator "" sv(const char* str, size_t len) noexcept; |
(1) | (since C++17) |
constexpr u8string_view operator "" sv(const char8_t* str, size_t len) noexcept; |
(2) | (since C++20) |
constexpr u16string_view operator "" sv(const char16_t* str, size_t len) noexcept; |
(3) | (since C++17) |
constexpr u32string_view operator "" sv(const char32_t* str, size_t len) noexcept; |
(4) | (since C++17) |
constexpr wstring_view operator "" sv(const wchar_t* str, size_t len) noexcept; |
(5) | (since C++17) |
Forms a string view of a character literal.
1) returns std::string_view{str, len}
2) returns std::u8string_view{str, len}
3) returns std::u16string_view{str, len}
4) returns std::u32string_view{str, len}
5) returns std::wstring_view{str, len}
Contents |
Parameters
str | - | pointer to the beginning of the raw character array literal |
len | - | length of the raw character array literal |
Return value
The string_view literal.
Notes
These operators are declared in the namespace std::literals::string_view_literals
, where both literals
and string_view_literals
are inline namespaces. Access to these operators can be gained with using namespace std::literals, using namespace std::string_view_literals, and using namespace std::literals::string_view_literals.
Example
Run this code
#include <string_view> #include <iostream> int main() { using namespace std::literals; std::string_view s1 = "abc\0\0def"; std::string_view s2 = "abc\0\0def"sv; std::cout << "s1: " << s1.size() << " \"" << s1 << "\"\n"; std::cout << "s2: " << s2.size() << " \"" << s2 << "\"\n"; }
Possible output:
s1: 3 "abc" s2: 8 "abc^@^@def"
See also
constructs a basic_string_view (public member function) |