Desmond Gold
Desmond Gold

Reputation: 2095

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:

Upvotes: 12

Views: 2739

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474266

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.

Upvotes: 15

Related Questions