glibmm: Glib::StdStringView Class Reference

glibmm 2.66.10

Public Member Functions | List of all members
Glib::StdStringView Class Reference

Helper class to avoid unnecessary string copying in function calls. More...

`#include <glibmm/ustring.h>`

## Public Member Functions
| StdStringView (const std::string & s)
| StdStringView (const char * s)
const char * | c_str () const

## Detailed Description

Helper class to avoid unnecessary string copying in function calls.

A Glib::StdStringView holds a const char pointer. It can be used as an argument type in a function that passes a const char pointer to a C function.

Unlike std::string_view, Glib::StdStringView shall be used only for null-terminated strings.

std::string f1(Glib::StdStringView s1, Glib::StdStringView s2);
// can be used instead of
std::string f2(const std::string& s1, const std::string& s2);
std::string
basic_string< char > string
Glib::StdStringView
Helper class to avoid unnecessary string copying in function calls.
Definition ustring.h:82

The strings are not copied when f1() is called with string literals.

auto r1 = f1("string 1", "string 2");

To pass a Glib::ustring to a function taking a Glib::StdStringView, you may have to use Glib::ustring::c_str().

std::string str = "non-UTF8 string";
Glib::ustring ustr = "UTF8 string";
auto r1 = f1(str, ustr.c_str());
Glib::ustring
Glib::ustring has much the same interface as std::string, but contains Unicode characters encoded as ...
Definition ustring.h:327
Glib::ustring::c_str
const char * c_str() const

Since glibmm 2.64

## Constructor & Destructor Documentation

## ◆ StdStringView() [1/2]

Glib::StdStringView::StdStringView | ( | const std::string & | s | ) |
| inline

## ◆ StdStringView() [2/2]

Glib::StdStringView::StdStringView | ( | const char * | s | ) |
| inline

## Member Function Documentation

## ◆ c_str()

const char * Glib::StdStringView::c_str | ( |  | ) | const
| inline