xxxxxxxxxx
import std.stdio : writeln;
import std.range : iota;
import std.algorithm : map;
import std.range : ElementType, front, empty;
import std.traits : Unqual;
import std.functional : forward;
struct X(R)
{
private:
alias Range = Unqual!R;
alias El = Unqual!(ElementType!Range);
Range _range;
public:
bool isValid() const
{
return !_range.empty;
}
El first() const
{
return _range.front;
}
}
auto makeX(R)(auto ref R r)
{
return X!(R)(forward!r);
}
void main()
{
auto range = [0,1,2,3].map!"a^^2";
auto x = range.makeX;
range.writeln;
x.empty.writeln;
}