Algorithms should be free from rich types

Steven Schveighoffer schveiguy at gmail.com
Fri Jun 30 02:25:27 UTC 2023


On 6/29/23 10:15 PM, Steven Schveighoffer wrote:

> 
> ```d
> auto usePrivate(T)(ref T thing) @system
> {
>     static struct GetMeThePrivateStuff
>     {
>       @disable this(this); // shouldn't be copied about, meant to be a 
> temporary access
>       private T* _thing; // "private" lol
>       auto ref opDispatch(string s, Args...)(Args args)
>       {
>          static if(Args.length == 0)
>             return __traits(getMember, *_thing, s);
>          else
>             return __traits(getMember, *_thing, s)(args);
>       }
>     }
> 
>     return GetMeThePrivateStuff(&thing);
> }
> ```

Oh wait, the `__traits(getMember)` trick doesn't work on member 
functions, interesting...

So maybe half-powerful ;)

-Steve


More information about the Digitalmars-d mailing list