digitalmars.D.learn - Range returned by iota and const
- =?ISO-8859-1?Q?Andr=E9_Stein?= (10/10) Apr 17 2012 Hi,
- Jonathan M Davis (8/18) Apr 17 2012 Very little on ranges ends up being marked const, because const ranges t...
Hi, I'm trying to pass the range returned by iota to a function accepting the parameter as const. I got compilation errors when trying to use the index operator and after some investigation it turned out that opSlice of iota.Result isn't declared as const. The function body of opSlice of iota.Result doesn't seem to mutate the range so is there any special reason why it isn't declared as such? (the same holds for opSlice). Regards, André
Apr 17 2012
On Tuesday, April 17, 2012 19:22:30 André Stein wrote:Hi, I'm trying to pass the range returned by iota to a function accepting the parameter as const. I got compilation errors when trying to use the index operator and after some investigation it turned out that opSlice of iota.Result isn't declared as const. The function body of opSlice of iota.Result doesn't seem to mutate the range so is there any special reason why it isn't declared as such? (the same holds for opSlice).Very little on ranges ends up being marked const, because const ranges tend to be useless (since you can't iterate over them). There are a few cases where you could use a range function even if the range is const (this at least appears to be one of them), but const typically gets forgotten simply because const ranges are generally useless. You can open an enhancement request ( d.puremagic.com/issues ) for this though. - Jonathan M Davis
Apr 17 2012