C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Type-safe printf and auto

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 12 Mar 2023 09:47:59 -0700
On Sunday, 12 March 2023 09:38:02 PDT Robin Rowe via Std-Proposals wrote:
> Wish we could do this:
>
> auto i = sizeof(int);
> printf("Value is %?, name is %??, type is %???",i,i,i);
>
> output: Value is 4, name is i, type is unsigned
>
> Furthermore, in C++ code it could be nice if printf gave the same output
> as cout for user-defined types:
>
> Point point(0,0,0);// My class Point with operator<<
> cout << point << endl;
> printf("%?\n",point);
>
> output: (0,0,0)
> (0,0,0)
>
> Thoughts? Suggestions?

Have you looked at std::format? It's part of C++20.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-03-12 16:48:01