r/cpp • u/eisenwave WG21 Member • Aug 18 '26
P4444: std::big_int
https://isocpp.org/files/papers/D4444R0.htmlHey folks! Matt Borland, Christopher Kormanyos, and I are working on bringing infinite-precision integers to C++29. We now have a D4444R0 draft of a paper that should be in the next mailing.
We could really use some feedback so that the published R0 is as polished as possible. Any thoughts on the paper and on the reference implementation are greatly appreciated.
It would also be very helpful if you tested out whether our big_int implementation works for you. We're in need of some real deployment experience. If you're currently using Boost.Multiprecision, the library should be a drop-in replacement for cpp_int for the most part.
View all comments
Show parent comment
2
u/n1ghtyunso Aug 18 '26
I know that solving the problem in general is not really right around the corner, unfortunately.
I am not typically someone standing against smaller improvements over an all-or-nothing approach, but this time I genuinly feel like its not that useful.
As you said, technically its the same story for
std::stringright now.If I need a string at compile time, i'll have to make sure I can do that.
And the most portable way to do that is not by using
constexpr std::stringdirectly.Which IS unfortunate, but currently thats just the way it is.
But for
std::big_intI believe it is the same situation.If I want that as a constexpr value, I will explicitly make sure it works.
Thats exactly why I do like the ability to customize the inplace storage size.
Having
big_intautomaticallyshrink_to_fitduring constant evaluation does not universally solve the problem,it simply lets the user code avoid thinking about it so long as it "happens to work".
Not mandating the automatic implicit
shrink_to_fitdoes have the same effect, but "happens to work" in less cases of course.std::stringdoes not have it either (obviously, because SSO is purely QoI), so doing actual string operations is almost certainly not going to produce a constexpr-compatiblestd::stringvalue.And there is no expectation of doing so either, really.
I see with
std::big_int, you would have the opportunity to change this.But I don't think this is something that should be relied upon to begin with,
because it will inevitably have situations where that no longer works too.
The only difference is that we can make it work again by tweaking the inplace storage parameter, which
std::stringdoes not expose at all.And that is a very valuable thing imo.
This lets me more directly express in code what my needs, my requirements are.
I know getting the required size into the capacity template argument is ALSO still clunky, unfortunately.
But at least the approach works for all representation sizes.
I am not sure if standardizing THAT would be possible or even of interest instead, though.
It's certainly out of scope for the
big_intpaper.