How do I generate `setX` methods for all private mutable variables in a class?

Basile B. b2.temp at gmx.com
Tue Jun 6 16:13:45 UTC 2023


On Tuesday, 6 June 2023 at 14:23:59 UTC, Steven Schveighoffer 
wrote:
> On 6/5/23 11:33 AM, Basile B. wrote:
>> [...]
>
> Ugh, don't do it that way. Always give opDispatch a template 
> constraint or it will suck to use.
>
> Also, given the problem constraints, you can build the method 
> automatically using the string.
>
> ```d
> auto opDispatch(string member, T)(auto ref T t) 
> if(member.startsWith("set"))
> {
>    mixin(toLower(m[3]), m[4 .. $], " = t;");
> }
> ```
>
> -Steve

yeah I know that opDispatch is disliked because it is tried in a 
SFINAE fashion, as citicized by Adam. But on the other side it's 
the best opover.


More information about the Digitalmars-d-learn mailing list