On 03/10/2014 11:23 a.m., Felipe Magno de Almeida wrote:
> Hello,
>
> On Fri, Oct 3, 2014 at 11:07 AM, Agustín K-ballo Bergé
> <
kaba...@hotmail.com> wrote:
>> On 03/10/2014 10:18 a.m., Vittorio Romeo wrote:
>>>
>>> (Sorry for the double post, I misclicked.)
>>>
>>> |
>>> structMultiDimArray
>>> {
>>> auto&operator[](std::size_t mX,std::size_t mY)// currently not valid
>>> {
>>> // ...
>>> }
>>> };
>>>
>>> MultiDimArraymda;
>>> mda[1,5]=10;
>>> |
>>>
>>> I agree with this suggestion, it would be a nice addition to the language.
>>
>>
>> This would be inconsistent with the way builtin arrays work.
>
> And what would be the problem with that? People don't use the
> subscript operator just for arrays. Whoever wants syntax consistency
> with arrays can do that already returning a proxy.
Teachability (new gotchas).
>> I would expect the syntax to call that overloaded subscript operator
>> to be `mda[1][5]` instead. The other alternative, to change the way
>> array indexing works, would be a breaking change and a needless
>> incompatibility with C, so I think it would have a much lesser change
>> of success.
>
> That would be even worse because we would have two ways to
> accomplish the same syntax.
We already have lots of ways of accomplishing the same syntax (and not
two are exactly the same). If, on the other hand, you are referring to
more than one syntax with the same effect (array[1][5] and array[1,5]),
I agree, I am not suggesting that.
> And having multiple arguments inside
> the subscript operator would be *very* useful for EDSLs.
I cannot take this argument seriously. People writing EDSLs better know
what they are dealing with, users of the subscript operator need not to.
I don't think it would be reasonable to complicate the language for
everyone for no apparent benefit other than simplifying an already
complex use case (that would remain complex) for a minority.