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

2021-12-12 Thread Imperatorn via Digitalmars-d-learn
On Sunday, 12 December 2021 at 14:26:54 UTC, Martin B wrote: On Sunday, 12 December 2021 at 14:11:48 UTC, Paul Backus wrote: You can use a [template constraint][1]: Hi Paul, yes! thats it, Thanks. I am facepalming me right now because have been on that webpage and missed that point.

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

2021-12-12 Thread Martin B via Digitalmars-d-learn
On Sunday, 12 December 2021 at 14:11:48 UTC, Paul Backus wrote: You can use a [template constraint][1]: Hi Paul, yes! thats it, Thanks. I am facepalming me right now because have been on that webpage and missed that point.

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

2021-12-12 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 12 December 2021 at 13:42:08 UTC, Martin B wrote: On Sunday, 12 December 2021 at 13:21:06 UTC, Adam D Ruppe wrote: On Sunday, 12 December 2021 at 13:11:58 UTC, Martin B wrote: Just add a forwarding overload: Hi Adam, i am wondering if there is another possibility without having to

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

2021-12-12 Thread Martin B via Digitalmars-d-learn
On Sunday, 12 December 2021 at 13:21:06 UTC, Adam D Ruppe wrote: On Sunday, 12 December 2021 at 13:11:58 UTC, Martin B wrote: Just add a forwarding overload: Hi Adam, i am wondering if there is another possibility without having to create overloads for each parameter type - something like

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

2021-12-12 Thread Adam D Ruppe via Digitalmars-d-learn
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)); }

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

2021-12-12 Thread Martin B via Digitalmars-d-learn
Hi everyone, lets say that required is a setter method: ``` Nullable!string str(Nullable!string setter) { return this._str = setter; } ``` The user should be able to: ``` auto a = new A(); a.str = "abc"; ``` As the setters parameter is defined to be of type `Nullable!string`, the compiler