Checking function parameters in Phobos

Marco Leise Marco.Leise at gmx.de
Mon Nov 25 04:00:37 PST 2013


Am Fri, 22 Nov 2013 02:55:44 +0100
schrieb Simen Kjærås <simen.kjaras at gmail.com>:

> On 22.11.2013 00:50, Meta wrote:
> > 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
> 
> I believe inout's point was this, though:
> 
>    Validated!(isPositive, lessThan42, int) i = foo();
> 
>    Validated!(isPositive, int) n = i; // Fails.
>    Validated!(lessThan42, isPositive, int) r = i; // Fails.
> 
> This is of course less than optimal.
> 
> If a type such as Validate is to be added to Phobos, these problems need 
> to be fixed first.

Can you write a templated assignment operator that
accepts any Validated!* instance and builds the set difference
of validation functions that are missing on the assigned value?
E.g. in the case of n = i: {isPositive} / {isPositive,
lessThan42} = emtpy set.

-- 
Marco



More information about the Digitalmars-d mailing list