C++ Logo


Advanced search

Re: [std-proposals] D2879R0 Proposal of Pythonesque std::print extensions LIVE LINK

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Fri, 12 May 2023 23:37:44 -0400
On Fri, May 12, 2023 at 11:23 PM Andrew Tomazos <andrewtomazos_at_[hidden]>

> The community considers std::print a new and better replacement of
> std::cout, not an addition.

Uh, one person isn't "the community."

> I suspect the difference between [Andrew's] proposed:
> std::println(1,2,3);
> and the equivalent:
> std::cout << 1 << " " << 2 << " " << 3 << std::endl;
> and their relationship to the Python:
> print(1,2,3)
> is plain to see.

Right, one is equivalent to the Python and the other isn't.
If you really want to reserve the name std::print for something exactly
equivalent to Python print, then you need to get on that ASAP and propose a
*different* syntax for C++'s equivalent of Python's "{} {}" % (1, 2) operator.
Because as it stands right now, my impression is that C++23 is 99.9999% out
the door already, with std::format remaining the C++ equivalent of Python's
%, and std::print meaning "std::cout << std::format".

For example, you might propose that
    "string literal" % (args...)
should be the new shorthand for
    std::format("string literal", args...)
That would let you write
    puts("string literal" % (args...));
in place of today's
    puts(std::format("string literal", args...));
or C++23's
    std::println("string literal", args...);

But I don't think any such proposal has any real chance of success. It
would mean undoing a lot of stuff that is *already in C++23* (IIUC), and
also inventing this new syntax (which as I've written it here, involves
core-language changes that interact with the library, and that's a huge

Anyway, the main takeaway here is that just *having `std::print` change its
behavior depending on the contents of its first string argument* is an
absolute 100% non-starter.


Received on 2023-05-13 03:37:56