C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [Draft] Typed and Safer Stream API for C++

From: Jerome Saint-Martin <jerome.saint-martin_at_[hidden]>
Date: Sat, 6 Sep 2025 18:08:16 +0000
Hi Thiago,
Thanks for your thoughtful response. I just wanted to clarify that my proposal was never intended to replace the existing API based on std::ios::openmode. I fully agree that dynamic composition of flags is essential and cannot be expressed at compile time — which is precisely why the old API must remain.
What I’m suggesting is a parallel API, designed for the simpler, static cases where compile-time safety and readability are beneficial. Much like how std::span complements raw pointers without replacing them, this new interface could offer:

  * -Cleaner syntax for common use cases (open_file("data.txt"))
  * -Compile-time validation of mode combinations
  *
-A gentler learning curve for newcomers
  *
In short, it’s not about removing flexibility — it’s about offering a more expressive and safer alternative when the use case allows it. For anything dynamic, the traditional API remains the right tool.
  *
Thanks again for engaging with the idea!
  *
Best regards,
Jerome
  *



________________________________
De: Std-Proposals <std-proposals-bounces_at_[hidden]> de la part de Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]>
Envoyé: Samedi 06 septembre 2025 17:13
À: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Thiago Macieira <thiago_at_[hidden]>
Objet: Re: [std-proposals] [Draft] Typed and Safer Stream API for C++

On Saturday, 6 September 2025 04:05:58 Pacific Daylight Time Jerome Saint-
Martin via Std-Proposals wrote:
> auto f = open_file<Mode::read>("data.txt");
> auto g = open_file<write | Mode ::binary>("log.bin");

We'll never get rid of the old API with this, because we may have:

  std::ios::openmode mode = std::ios::in | std::ios::binary;
  if (rw)
      mode |= std::ios::out;
  if (trunc)
      mode |= std::ios::trunc;

since the above can't be done at constexpr time, either the old API must still
be taught or we'd have to write a 2^N combination of the new open_file<> calls.

And if we need to teach an API, we'll end up with the simplest.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Platform & System Engineering

Received on 2025-09-06 18:08:23