Templates and unaryFun!

ddcovery antoniocabreraperez at gmail.com
Thu Sep 24 14:15:01 UTC 2020


I think I will dedicate tonight one or two hours to understand 
the first two proposals :-D.

On Thursday, 24 September 2020 at 13:28:25 UTC, WebFreak001 wrote:
> [...]
> Alternatively a lot easier would be to just return auto and do:
>
> auto dt(alias fun, T)(Dot!T t){
> 	return t.dot(t => unaryFun!fun(t));
> }
>
> This doesn't allow users to overwrite the return type exactly 
> but it simplifies implementation and doesn't look like it would 
> generate any double instantiation.
> [...]

Following your last recommendation, I included de auto version as 
a Dot(T) member:

> auto d(alias fun)()
> {
>   return dot(a => unaryFun!fun(a));
> }

And the syntax is really compact:

>
> assert( 
> dot(p).d!"a.father".d!"a.father".d!"a.name".d!"a.length".get(0) 
> == 0);
>
> assert( 
> dot!Person(null).d!"a.father".d!"a.father".d!"a.father".d!"a.name".get == null);
>

Great help WebFreak001. Thank you very much !!!



More information about the Digitalmars-d-learn mailing list