
On 08/26/11 17:56, Agustín K-ballo Bergé wrote:
On 26/08/2011 15:04, Larry Evans 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
-regards, Larry
Now that you mention this, I have considered the same issue currently being discussed when trying to implement a multi-dimensional subscript operator facade. Initially I started invoking the function as soon as there were enough arguments (using Eric's technique); but then I considered several overloads with different number of arguments and the only solution I could came with was invoking the underlying function on a conversion operator, which would do more harm than good (specially considering C++0X auto). Eventually I simply had to discard this use case scenario. Then for curried functions, explicit invocation via () seems like a viable solution to the problem.
I encountered a somewhat similar problem when implementing a multi-dimensional array where the number of dimensions was determined only at run-time. Thus, the number of indices needed to get an actual value out instead of a subarray was unknown until runtime. As a workaround, both: operator[](undigned I) and: operator()() were defined for the array. The latter just assumed all the remaining indices were 0 and returned that result. The former (the operator[]) returned a subarray. I don't think there was any check for too many indices (it was just a prototype). Code is here: http://svn.boost.org/svn/boost/sandbox/variadic_templates/sandbox/stepper/bo... -regards, Larry