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: Sun, 7 Sep 2025 12:46:58 +0000
The point is precisely that allowing std::ios::out as a flag when constructing an ifstream is misleading. It compiles, which implies that writing might be possible — but it doesn’t work, because ifstream is inherently a read-only stream. That’s what I meant by 'illogical mode combinations': the API permits a flag that contradicts the semantics of the type.
Ideally, such contradictions should be caught at compile-time, or at least discouraged by the design. Otherwise, developers are left with silent failures and confusing behavior.

Jérôme

________________________________
De: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Envoyé: Dimanche 07 septembre 2025 14:31
À: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Jonathan Wakely <cxx_at_[hidden]>; Jerome Saint-Martin <jerome.saint-martin_at_[hidden]>; Matthieu Terrier <mterrier_at_[hidden]>; Caroline Pierron <caroline.pierron_at_[hidden]>; Madelenat, Christophe <christophe.madelenat_at_[hidden]>
Objet: Re: [std-proposals] [Draft] Typed and Safer Stream API for C++

On Sun, 7 Sept 2025 at 15:07, Jerome Saint-Martin via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> I see you prefer personal attacks over technical discussion. I never claimed that ifstream doesn't work—only that some flags seemed redundant.

Perhaps you can then claim what this bit you wrote means:

>Problem
>The current ifstream/ofstream API allows illogical mode combinations:
> std::ifstream f("data.txt", std::ios::out); // Compiles, but doesn't work

See the "Compiles, but doesn't work" part.

What exactly do you suggest can be validated at compile-time? How is a
combination of read and write modes illogical?

Received on 2025-09-07 12:47:02