On 05.10.2017 12:07, nkm1 wrote:
Am I missing something? You can already extend the original struct:
extern(c) struct Crng
{ int seedA;
int seedB;
ubyte[] restOfTheData;
extern (D) {
// or without extern (D)...
auto front() { return current(&this); }
void popFront() { toNextValue(&this); }
}
}
What does it matter if you put your extension functions inside the
struct or outside of it? (same question to Timon)
For example:
- Methods force the 'this' argument to be references (for structs) or
values (for classes).
- Adding functionality to a type in the module where it is defined is
not the only use case. Wrapper types can be more cumbersome to use than
the original type.