On Thursday, 5 October 2017 at 08:27:14 UTC, Dukc wrote:
and you have to rewrite many wrappers for Crng functions
despite the alias this because they either require return Crng
or gequire a pointer to one. This needs to be defined manually
for example:
Crng initByTime(int time){return Crng(crng.initByTime(time))};
With ADL it would be enough to extend the original struct with
range primitives:
auto front(Crng range){return current(*range);}
void popFront(ref Crng range){toNextValue(*range);}
//...
With current semantics the latter example will work only with
locally defined range function templates. Not with Phobos ones,
because they cannot see the extension functions.
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). Unless you
also propose "extending" the modules themselves (like reopening
namespaces in C++? This is a whole another can of worms...)
Looks like what most people want are extension methods, not ADL?