On Tuesday, 15 May 2018 at 06:38:04 UTC, KingJoffrey wrote:
Can you give me some examples?

Defining a Voldemort type (meaning, one whose name is not public) with private members for use by multiple functions:

-------
module two_functions;

private struct MyForwardRange
{   private int function(int[]) cumulator;
    int[] front;
    void popFront()
    {   front ~= cumulator(front);
    }
    enum empty = false;
    auto save()
    {   return this;
    }
}

auto accumulate(int a, int b)
{   import std.algorithm;
    return MyForwardRange(arr => arr.sum, [a, b]);
}

auto extendByIota(int[] startElems)
{   return MyForwardRange(arr => arr.length, startElems);
}
-------

In a simple module like this, it would be needless complexity to make cumulator have a package visibility and put the functions in a different module. That's what you would have to do if private meant private to class, not to module.

Reply via email to