C++ Logo

std-proposals

Advanced search

Re: std::max_format_size pre-proposal

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sat, 20 Mar 2021 09:57:46 -0400
The `to/from_chars` interface explicitly avoids the use of templates.
Or rather, the in-specification definition of it does. There's not
really a simple way to avoid that here without introducing a bunch of
function names for no reason.

I think the reasoning behind not using templates was to make it more
acceptable for C to implement the interface. However, the `constexpr`
nature of these APIs makes a non-macro C equivalent API impossible, so
you may as well use template arguments.

You note in the proposal that you could use `formatted_size`, but you
couldn't, as even if it were `constexpr`, it is still computing the
size of a specific value. You're interested in the maximum possible
size.

As to the location of these functions, they should go into the
`charconv` header and the `format` header, since both of them consume
these values. Sticking them in `limits` doesn't really make sense,
since these values are about formatting more than numeric limitations
(that's why they require additional parameters and are functions
rather than variables). Also, it would require that `limits`
include/export parts of `charconv`, since these APIs use
`std::char_format`.

Received on 2021-03-20 08:57:59