Checking function parameters in Phobos

Meta jared771 at gmail.com
Thu Nov 21 15:50:31 PST 2013


On Thursday, 21 November 2013 at 22:51:43 UTC, inout wrote:
> What if you have more that just one validation, e.g. Positive 
> and LessThan42?
> Is Positive!LessThan42!int the same type as 
> LessThan42!Positive!int? Implicitly convertible?

Allow multiple validation functions. Then a Validated type is 
only valid if validationFunction1(val) && 
validationFunction2(val) &&...

Validated!(isPositive, lessThan42, int) validatedInt = 
validate!(isPositive, lessThan42)(34);
//Do stuff with validatedInt

Or just pass a function that validates that the int is both 
positive and less than 42, which would be much simpler.

> ...
>
> It also doesn't involve creating new types.

Creating new types is what allows us to provide static, 
compiler-verified guarantees.


More information about the Digitalmars-d mailing list