Boost logo

Boost :

Subject: Re: [boost] [xint] Boost.XInt formal review
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2011-03-07 11:21:34


On Mon, 7 Mar 2011 09:08:33 -0500
"Stewart, Robert" <Robert.Stewart_at_[hidden]> wrote:

[...]
>>> - pow2, factorial, nan: Same deal. I don't see a problem
>>> with making these free functions and specifying the desired
>>> return value as an explicit template parameter. It will
>>> look the same but make the interface more uniform:
>>> typedef integer_t< ... > integer_type;
>>> integer_type x = integer_type::pow2(n);
>>> vs
>>> typedef integer_t< ... > integer_type;
>>> integer_type x = pow2< integer_type >(n);
>>
>> I could easily argue either side of that one. When I originally
>> wrote that code, the current method seemed ever-so-slightly more
>> appealing; now I think the way that you're advocating might be.
>
> I'd rather algorithms be separate. Even if you find that an
> efficiency problem, it should merely be seen as a catalyst to expand
> the integer_t interface to regain the lost efficiency.

That's three votes in favor of changing it, counting my own altered
opinion. I'll put it on the list.

>>> Chad already knows my feelings on COW, but to be explicit:
>>> I'm not necessarily against use of COW in general, but I
>>> have yet to be given a use case where COW would outperform
>>> move emulation in theory.
>>
>> I've located two: abs and negate. [...] Both involve changes to the
>> sign bit only, and one only sometimes needs to alter it. [...]
>
> You can do the same, I should think, without COW. All you need is to
> make your algorithms less naive. The algorithms can manage the sign
> in a separate variable and refer to an existing magnitude or make a
> copy, as needed, unless I'm much mistaken. That is a little less
> convenient, but should obviate COW.

Certainly it could be done without CoW. In an earlier iteration, I had
a special subclass for that specific purpose, which kept a reference to
an existing integer and a separate negate-the-sign Boolean. But if you
work out the implementation, you'll see that it's essentially a
poor-man's version of CoW anyway. Arguably less efficient, and
definitely less aesthetically appealing, so I replaced it with a true
CoW implementation.

-- 
Chad Nelson
Oak Circle Software, Inc.
*
*
*



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk