My template tuple code does not compile

Q. Schroll qs.il.paperinik at gmail.com
Wed Feb 27 19:29:54 UTC 2019


On Wednesday, 27 February 2019 at 03:53:35 UTC, Victor Porton 
wrote:
> After following your suggestion to rewrite it with Stride it 
> does not work either. I assume the error is somehow related to 
> allSatisfy!.
>
> https://github.com/vporton/struct-params-dlang/blob/c1adc86672f46fd6b743903cc270dceef120a8fe/source/struct_params.d
>
> Please help. It is important for both D community and world at 
> large.

In

     static assert(allSatisfy!(x => isType!x, Types) && ...

you use `allSatisfy` as if it took a lambda function or something 
like that. It does not. It takes a expects a template.

First things first: The spec¹ says that allSatisfy!(F, T) «tests 
whether all given items satisfy a template predicate, i.e. 
evaluates to F!(T[0]) && F!(T[1]) && ... && F!(T[$ - 1]).» Here, 
`F` is not a lambda, it's a template.

In your case, you can use `isTypeTuple!Types` from the library² 
to check what you intend to check. For the values, unfortunately 
there is no library function to check that they are all strings. 
A specific solution is to use a (static) template

     enum bool isStringValue(alias x) = is(typeof(x) == string);

and feed it to `allSatisfy`:

     allSatisfy!(isStringValue, Names)

¹ https://dlang.org/library/std/meta/all_satisfy.html
² https://dlang.org/phobos/std_traits.html#isTypeTuple




More information about the Digitalmars-d-learn mailing list