Date: Thu, 02 Apr 2026 15:49:46 +0000
On Thursday, April 2nd, 2026 at 6:03 PM, Jan Schultke <janschultke_at_[hidden]> wrote:
> I feel like the cost of having this whole new view type is higher than just
> adding a couple of boilerplate overloads.
Yeah, I agree that it's not 100% that the extra complexity of an additional
type is worth it.
> You also need to consider that operator+ should work if one of the operands
> is an integer. I think to handle that without avoidable overhead, you
> actually need operator+ to be a function template. The reason is that for
> example, __int128 may not fit into big_int without extra allocation,
> so (big_int +
> __int128) would require an extra allocation to fit the right side, even
> though the operation could be performed with only the left allocation
> involved. I don't think big_int_view can handle the __int128 case in any
> reasonable way; you cannot do that without ownership.
The way I picture it, initializing a big_int_view from an integer is the same
as initializing a big_int from an integer: it allocates (or not) and takes
ownership of the value. It doesn't save you the overhead that specific __int128
overloads/template would.
> I feel like the cost of having this whole new view type is higher than just
> adding a couple of boilerplate overloads.
Yeah, I agree that it's not 100% that the extra complexity of an additional
type is worth it.
> You also need to consider that operator+ should work if one of the operands
> is an integer. I think to handle that without avoidable overhead, you
> actually need operator+ to be a function template. The reason is that for
> example, __int128 may not fit into big_int without extra allocation,
> so (big_int +
> __int128) would require an extra allocation to fit the right side, even
> though the operation could be performed with only the left allocation
> involved. I don't think big_int_view can handle the __int128 case in any
> reasonable way; you cannot do that without ownership.
The way I picture it, initializing a big_int_view from an integer is the same
as initializing a big_int from an integer: it allocates (or not) and takes
ownership of the value. It doesn't save you the overhead that specific __int128
overloads/template would.
Received on 2026-04-02 15:49:55
