Restrict type of function parameter to a defined list of types?

Adam D Ruppe destructionator at gmail.com
Sun Dec 12 13:21:06 UTC 2021


On Sunday, 12 December 2021 at 13:11:58 UTC, Martin B wrote:
> Hi everyone,
>
> lets say that required is a setter method:
> ```
> Nullable!string str(Nullable!string setter) {
>     return this._str = setter;
> }
> ```


Just add a forwarding overload:

auto str(string s) { return this.str(nullable(s)); }


Then the user can pass either Nullable or string but not other 
things.


More information about the Digitalmars-d-learn mailing list