C++ Logo


Advanced search

Subject: Re: [isocpp-lib-ext] Review of P2093R2: Formatted output
From: Tom Honermann (tom_at_[hidden])
Date: 2020-12-05 16:16:06

On 12/5/20 4:31 PM, Jens Maurer wrote:
> On 05/12/2020 22.16, Tom Honermann wrote:
>> On 11/28/20 11:33 AM, Victor Zverovich wrote:
>>>> And then there is the facility of converting the C++ literal encoding to the console encoding, if necessary.  Again, this should be a separate facility, preferably offering a generic transcoding facility that can be specialized for the console-only use case.
>>> While I agree that such a transcoding facility would be useful I think it is out of scope of the current paper. The latter requires only minimal transcoding facilities for the Unicode case and only on some platforms where dedicated system APIs exist.
>> I agree that distinct interfaces should be provided for each of these concerns, but I also think each can be pursued separately and need not hold up the proposed feature.  We can always re-specify the proposed behavior in terms of new interfaces via as-if in the future.
> Let me disagree here. It took years for to_chars (the underlying
> elementary operation) to arrive after std::to_string was standardized.
> I have no objection to providing high-level facilities in C++,
> but I want the option to ignore those high-level facilities
> if need be. Apparently, there is an appetite to differentiate
> "writing to the console" vs. "writing to a file", and that
> appears to be a useful low-level query to have.

I agree that it is useful to have.  But it is also functionality that
has been readily available for most systems for a long time now and
there hasn't been a push to standardize it in C or C++ thus far.  I'm
not opposed to adding it at all, I just don't want the lack of it to
hold up Victor's proposal.  At any rate, here is a fairly portable
(untested) implementation (with lax error handling) for C style streams
(the Windows implementation would be better implemented using whatever
Win32 features _isatty() uses).

    #if defined(_XOPEN_SOURCE)
    #include <stdio.h>
    #include <unistd.h>
    #elif defined(_MSC_VER)
    #include <io.h>

    bool is_attached_to_terminal(FILE* fp) {
    #if defined(_XOPEN_SOURCE)
     Â  return isatty(fileno(fp));
    #elif defined(_MSC_VER)
     Â  return _isatty(_fileno(fp));


> Jens

SG16 list run by sg16-owner@lists.isocpp.org