On Tuesday, 14 June 2016 at 14:47:11 UTC, Steven Schveighoffer
wrote:
* only do one mutable version of opSlice
* add implicit cast (using "alias this") for const(Slice!T) ->
Slice!(const(T)).
Interesting, but unfortunately, the compiler isn't eager about
this conversion. auto x = s[5 .. 7] isn't going to give you a
Slice!(const(T)), like an array would. But I like the idea.
Hm, you are right, in fact it doesn't work. Somehow it seemed to
in my usecase. Well, triplicate it is then. Which isn't that bad
using something like
auto opSlice(size_t a, size_t b)
{
// actual non-trivial code
}
auto opSlice(size_t a, size_t b) const
{
return Slice!(const(T))(ptr, length).opSlice(a,b);
}
auto opSlice(size_t a, size_t b) immutable
{
return Slice!(immutable(T))(ptr, length).opSlice(a,b);
}