A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/aeron-io/simple-binary-encoding/issues/550 below:

string_view instead of char* for variable length strings · Issue #550 · aeron-io/simple-binary-encoding · GitHub

I nice optimization and/or enhancement would be to return std::string_view instead of const char* for variable length strings. Applications may wish to use a string without copying its bytes somewhere else.

To achieve this now, code must read and save the string's length, then read the string, then construct the string_view.

auto usernameLength = message.usernameLength();
std::string_view username(message.username(), usernameLength);

It cannot be done in a single line, because the length field must be read first. Also note that the length is copied into a uint32_t field twice, once in message.usernameLength() and a second time in message.username(). Returning std::string_view would eliminate one of the copies.

It would be nice to be able to do one of the following:

std::string_view username = message.username();

auto username = message.username();

This might require a C++17 compatibility flag of some kind.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4