short

Three small C++26 string fixes you will use every day

· english· audience: working-cpp· AI-generated, reviewed by Filip Sajdak

Most of the C++26 attention goes to reflection, contracts, and std::execution. But the standard also landed a batch of small string-library fixes (nicely catalogued by Sandor Dargo) that remove conversions you have been writing by hand for years. Here are the three you will hit most often, each verified on both GCC 16.1 and the Bloomberg clang-p2996 fork.

1. string + string_view finally compiles

This is the one that has bitten everyone. std::string_view arrived in C++17, but you could never concatenate it onto a std::string directly. The mix had no operator+, so you had to build a temporary std::string first.

std::string      hello{"hello "};
std::string_view world{"world"};

std::string greeting = hello + world;   // pre-C++26: ill-formed. C++26: works.

P2591R5 “Concatenation of strings and string views” adds free operator+ templates that accept anything convertible to string_view, in both orders, so you can even bracket a string with views:

std::string framed = std::string_view{"<< "} + greeting + std::string_view{" >>"};
// framed == "<< hello world >>"

2. A stringstream straight from a string_view

If you parse text, you have written std::istringstream in{std::string{some_view}} just to get a view into a stream. That temporary copy is gone. P2495R3 “Interfacing stringstreams with string_view” gives the whole stringstream family string_view constructors:

std::string_view csv{"12 34 56"};
std::istringstream in{csv};          // C++26: no temporary std::string

int a, b, c;
in >> a >> b >> c;                   // a+b+c == 102

3. A bitset from a string_view

Same story for std::bitset. Before C++26 you either built a temporary std::string or went through data(), which is a null-termination trap when the view is a slice of a larger buffer. P2697R1 “Interfacing bitset with string_view” adds the direct constructor:

std::string_view bits{"101010"};
std::bitset<6> b{bits};              // C++26: straight from the view

b.to_ulong();   // 42
b.count();      // 3

Why these matter

None of these change what your program does. They change how much boilerplate stands between you and it, and they delete temporary allocations that were pure friction. The string_view constructors in particular fix a real correctness hazard: every time you reached for .data() on a non-null-terminated view, you were one refactor away from reading past the end. C++26 closes that path off by giving you a constructor that knows the length.

The nicest part: all three are mainline standard-library changes, already shipping in GCC and Clang. No reflection fork, no experimental flag (the examples above just happen to be pinned to our C++26 toolchains). Turn on -std=c++26 and they are there.


Sources: Sandor Dargo, “C++26: string and string_view improvements”. Papers: P2591R5 (concatenation), P2495R3 (stringstreams), P2697R1 (bitset). Examples verified on Compiler Explorer with GCC 16.1 and the Bloomberg clang-p2996 fork.