
On 08/26/11 15:24, Dave Abrahams wrote:
on Fri Aug 26 2011, Larry Evans <cppljevans-AT-suddenlink.net> wrote:
Since an n-dimensional array can be thought of as a function of n indexes, I would think then that subscripting multi-dimensional arrays would rub you the wrong way:
int f[1][1][1];
f[0] => doesn't return an int f[0][0] => doesn't return an int f[0][0][0] => *does* return an int
Instead, would you prefer the following symmetrical version?
f[0] => doesn't return an int f[0][0] => doesn't return an int f[0][0][0] => doesn't return an int f[0][0][0]() => *does* return an int
No, sorry, but that's just silly. Array indexing is entirely consistent:
f[0] => returns int(&)[1][1] f[0][0] => returns int(&)[1] f[0][0][0] => returns int&
Then so is (using haskell notation): f :: X -> Y -> Z -> int f x => returns Y -> Z -> int f x y => returns Z -> int f x y z => returns int which is Eric's point. IOW, when supplied with enough arguments, the function returns the result_type of the function, just as, when a multi-dimensional array is supplied enough arguments (or indices) it returns the value type of the array. -Larry