On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote:
I currently have a situation where I want to have a function that accepts a parameter optionally.

I thought maybe Nullable!int might work:

void foo(Nullable!int) {}

void main()
{
   foo(1); // error
   int x;
   foo(x); // error
}


Can somebody enlighten me what this topic is about?

I thought an optional parameter would be as easy as

    void foo(int i = 0) { writeln(i); }

    void main()
    {
        int x;
        foo(x);
        foo(1);
        foo();
    }

Is the Nullable!int approach because 'i' would always "optionally" be 0 if not passed with above 'foo'?

Reply via email to