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


Author: Ron Natalie <ron@spamcop.net>
Date: Wed, 25 Oct 2006 15:47:39 CST
Raw View
John Nagle wrote:

>     foo[a,b]
>
> is an invocation of the comma operator which ignores a
> and is equivalent to

It doesn't ignore it, it evaluates it and then uses the
right hand operand to determine the value of the expression.

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

There's no such thing as a multidimensional array in C++.   Just
arrays of arrays.

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

Or how about the fact that C and C++ have never had that syntax.

---
[ 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                      ]





Author: alfps@start.no ("Alf P. Steinbach")
Date: Thu, 26 Oct 2006 17:38:00 GMT
Raw View
* Ron Natalie:
> John Nagle wrote:
>=20
>>     foo[a,b]
>>
>> is an invocation of the comma operator which ignores a
>> and is equivalent to
>=20
> It doesn't ignore it, it evaluates it and then uses the
> right hand operand to determine the value of the expression.

Right, although I suspect John meant this as an example of inadvertently=20
supplying two index values using syntax from some other language, in=20
which case the first value (no side effects) has no side effects and is=20
effectively ignored.


>> As a result, "operator[]" can only take one argument.  This
>> prohibits the creation of multidimensional array classes using
>> standard bracket syntax.
>=20
> There's no such thing as a multidimensional array in C++.   Just
> arrays of arrays.

Again, I think that's a misunderstanding.  First, about the terminology:

   int a[3][4];

might be described as multidimensional array, by someone favoring that=20
term.  For example, <url: http://www.research.att.com/~bs/array34.c>.

Or, for example, the standard's =A78.3.4/4, =ABWhen several "array of"=20
specifications are adjacent, a multidimensional array is created; ...".

Second, whatever we call the built-in features of the language, surely=20
that does not limit what we can call abstractions built upon those featur=
es.


>> The justification for this is protection of legacy code which
>> might conceivably use the comma operator within square brackets.
>=20
> Or how about the fact that C and C++ have never had that syntax.

If I'm not very mistaken, that was the point. ;-)

--=20
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

---
[ 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                      ]





Author: nagle@animats.com (John Nagle)
Date: Fri, 27 Oct 2006 02:43:42 GMT
Raw View
Me wrote:
> There are lambda and expression template libraries that abuse the array
> index operator because it relies on the fact that it doesn't behave
> like the function call operator. The immediate example that comes to
> mind:
>
> http://spirit.sourceforge.net/distrib/spirit_1_6_1/libs/spirit/phoenix/doc/statements.html

    That bit of wierdness dates from 2002.  Can you find a production use of
it in Google code search?

    Now that we have a big code archive available, we no longer have to
speculate about what gets used and what doesn't.  We can objectively
answer the 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                      ]





Author: pete.forman@westerngeco.com (Pete Forman)
Date: Mon, 30 Oct 2006 16:12:19 GMT
Raw View
nagle@animats.com (John Nagle) writes:

 > Now that we have a big code archive available, we no longer have to
 > speculate about what gets used and what doesn't.  We can objectively
 > answer the question.

At the risk of stating the obvious, that archive only holds public
source code.
--
Pete Forman                -./\.-  Disclaimer: This post is originated
WesternGeco                  -./\.-   by myself and does not represent
pete.forman@westerngeco.com    -./\.-   the opinion of Schlumberger or
http://petef.port5.com           -./\.-   WesternGeco.

---
[ 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                      ]