forward range properties with alias this - how?
Ivan Kazmenko via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 28 14:25:22 PDT 2015
Hello,
I wrap an array into a struct. Then I use alias this to expose
the array functionality. Sadly, range properties of the array
are not forwarded, and so I can't use the struct as an array with
functions from std.algorithm and std.range.
-----
import std.range, std.stdio;
struct S {
int[] contents;
alias contents this;
}
void main() {
S s;
writeln(hasSlicing!(S)); // false
}
-----
I would like to be able to do that, however.
1. Why exactly hasSlicing (et al.) does not check the alias
this-ed array when it checks the struct?
2. What should I do?
The solution I can think of is to insert the 3-6 range functions
which forward the functionality to the underlying array, perhaps
as a mixin.
Ivan Kazmenko.
More information about the Digitalmars-d-learn
mailing list