std.experimental.checkedint is ready for comments!

tsbockman via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 14 21:57:11 PDT 2016


On Wednesday, 15 June 2016 at 03:45:39 UTC, Walter Bright wrote:
> On 6/14/2016 8:23 PM, tsbockman wrote:
>> This is specified fully in the template constraints:
>>     if (isIntegral!N && isUnqual!N)
>>     if ((isIntegral!N && !isUnqual!N) || isCheckedint!N)
>>
>> The second overload simply forwards to the first, after 
>> applying
>> BasicScalar!(Unqual!N).
>
> Why would a checkedint be a base type for a checkedint?

Generic code (contrived, oversimplified example):

     import checkedint.throws, checkedint.traits;

     SmartInt!(typeof(A.init + B.init)) add(A, B)(const A a, const 
B b)
         if (isIntegral!A && isIntegral!B)
     {
         SmartInt!A ma = a;
         SmartInt!B mb = b;

         return ma + mb;
     }

Of course I could force the user to write `BasicScalar` 
everywhere - but why? The intent is just as clear this way, and 
it's less verbose.



More information about the Digitalmars-d mailing list