GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_string::operatorbasic_string_view(3) C++ Standard Libary std::basic_string::operatorbasic_string_view(3)

std::basic_string::operatorbasic_string_view - std::basic_string::operatorbasic_string_view


operator std::basic_string_view<CharT, Traits>() const noexcept; (since C++17)
(until C++20)
constexpr operator std::basic_string_view<CharT, Traits>() const (since C++20)
noexcept;


Returns a std::basic_string_view, constructed as if by std::basic_string_view<CharT,
Traits>(data(), size())


(none)


A string view representing the entire contents of the string.


It is the programmer's responsibility to ensure that the resulting string view does
not outlive the string.


std::string get_string();
int f(std::string_view sv);


int x = f(get_string()); // OK
std::string_view sv = get_string(); // Bad: holds a dangling pointer

// Run this code


#include <iostream>
#include <string>
#include <string_view>


void show_wstring_size(std::wstring_view wcstr_v)
{
std::cout << wcstr_v.size() << " code points\n";
}


int main()
{
std::string cppstr = "ラーメン"; // narrow string
std::wstring wcstr = L"ラーメン"; // wide string


// Implicit conversion from string to string_view
// via std::string::operator string_view:
std::string_view cppstr_v = cppstr;


std::cout << cppstr_v << '\n'
<< cppstr_v.size() << " code units\n";


// Implicit conversion from wstring to wstring_view
// via std::wstring::operator wstring_view:
show_wstring_size(wcstr);
}


ラーメン
12 code units
4 code points


constructor constructs a basic_string_view
(C++17) (public member function of std::basic_string_view<CharT,Traits>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.