-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Labels
Description
The following code does not compile.
struct Foo
{
ContiguousSlice!(1, int) bar;
int get(size_t i) const
{
return bar[i];
}
}
The problem is that .opIndex
cannot be called on a const
object. There is an easy workaround, namely bar.toConst[i]
. In other contexts, the toConst
is called automatically (using some alias this
construction). But here the compiler sees the non-const opIndex
method and gives an error before even trying to use the alias this
.
Calling toConst
explicitly is easy to do but kinda unintuitive, because it is used here to remove a const
attribute, not to add it. More precisely, it is used for the conversion from const Slice!int
to Slice!(const int)
.