xxxxxxxxxx
import std.stdio;
:
struct ScopeBuffer
{
this(char[4] buf, size_t len = 0)
{
this.buf = buf;
this.len = len;
}
char[] opSlice(size_t lower, size_t upper)
in
{
assert(lower <= len, "Lower bound must be less than or equal to the length");
assert(upper <= len, "Upper bound must be less than or equal to the length");
assert(lower <= upper, "Lower bound must be less than or equal to the upper bound");
}
do
{
return buf[lower .. upper]; // GOOD: Compiler error here
}
char[4] buf;
size_t len;
}
char[] fun()
{
char[4] buf = "abcd";
auto sb = ScopeBuffer(buf, 4);
return sb[0..2];
}
void main()
{
auto s = fun();
writeln(s);
}