There are plenty of questions related to operator[] only taking one argument, but I can't find one that actually says why.
For example, it seems a very natural extension of the language to have matrix[0, 3]
call an ElementT& operator[](SizeT x, SizeT y)
function.
Is there any particular reason (e.g. incompatibility) that this syntax isn't in the language, or anything besides lack of motivation actually preventing it from being added?
(Note: This has been marked a duplicate, but it is not. This question is "why isn't this syntax in the language?" not "how do I work around the issue?". As mentioned, there are plenty of questions that address the latter, but none that answer the former.)
Not only is the (little-used in this particular context) comma operator a wrench in the works which require a lengthy transition period to get this standardized, we already have another solution which people use:
ElementT& operator()(SizeT x, SizeT y)
Some matrix libraries in the wild use this form. It's a little ugly, but welcome to C++. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With