Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How will std::spanstream usually be used in C++?

<spanstream> will debut in C++23 (see cppreference). According to the proposal, they are string-streams with std::span based buffers.

My questions are:

  • Does std::spanstream have somewhat equivalent uses of the old std::strstream (or strstream deprecated in C++ 98)?
  • What will be the benefits of using them after the full release of C++ 23?
like image 369
Desmond Gold Avatar asked Dec 31 '22 14:12

Desmond Gold


1 Answers

They are intended to be a near drop-in replacement for strstream (except with proper bounds checking). As such, they will have the exact same use cases. When you have an existing buffer that you want to stream into/outof.

The ability to move a std::string into stringstreams added in C++20 eliminated the use case when the existing buffer is in a std::string. But sometimes you just have a naked char const* with a known length.

like image 141
Nicol Bolas Avatar answered Jan 02 '23 02:01

Nicol Bolas