Sealed classes - would you want them in D?
Dukc
ajieskola at gmail.com
Tue May 15 07:22:32 UTC 2018
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.
More information about the Digitalmars-d
mailing list