Topic: Comma within square brackets - not found in Google Code Search. Multi-argument


Author: nagle@animats.com (John Nagle)
Date: Wed, 25 Oct 2006 18:24:45 GMT
Raw View
One of the old issues that's come up a few times is whether
"operator[]" should have the same argument syntax as "operator()"
or regular function call syntax.  Currently,

 foo(a,b)

is a two-argument function call, while

 foo[a,b]

is an invocation of the comma operator which ignores a
and is equivalent to

 foo[b].

As a result, "operator[]" can only take one argument.  This
prohibits the creation of multidimensional array classes using
standard bracket syntax.

The justification for this is protection of legacy code which
might conceivably use the comma operator within square brackets.

But now we have Google Code Search, and can easily look for
such usages.  A search key to use is:

 ^[^\"/]*\[[^\[\]\(\),]*,[^\[\]\(\),]*\] lang:c++

This isn't perfect, but comes as close as we can get with regular expressions.
(The main problem is throwing out comments and quotes; there are about 12,000
occurences of commas inside square brackets inside quotes or comments.)

This gets us about 100 hits.

They're all in multline comments, Microsoft "@deftypefn" statements,
char constants, template type arguments or embedded assembler.

Try the search yourself.  Commas inside subscript expressions just
aren't being used in the visible universe of C++ code.

At last, we have the tools to dispose of this question.

    John Nagle
    Animats

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]