C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Comma within square brackets - not found in Google Code Sear

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
John Nagle
Guest





PostPosted: Wed Oct 25, 2006 11:24 pm    Post subject: Comma within square brackets - not found in Google Code Sear Reply with quote



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 ]
Back to top
Ron Natalie
Guest





PostPosted: Wed Oct 25, 2006 11:24 pm    Post subject: Re: Comma within square brackets - not found in Google Code Reply with quote



John Nagle wrote:

Quote:
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.

Quote:
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.

Quote:

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 ]
Back to top
Me
Guest





PostPosted: Thu Oct 26, 2006 6:24 am    Post subject: Re: Comma within square brackets - not found in Google Code Reply with quote



John Nagle wrote:
Quote:
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.

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.

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

---
[ 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 ]
Back to top
Aleksey Loginov
Guest





PostPosted: Thu Oct 26, 2006 3:45 pm    Post subject: Re: Comma within square brackets - not found in Google Code Reply with quote

John Nagle wrote:
Quote:
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].


Don't forget you can overload comma operator.
This can give interesting advantages.
Real life example (http://code.google.com/p/night-lambda/):

namespace pvt {

struct arg {} _1;

template<typename L, typename R>
typename append<L,R>::type oprerator , ( L &, R & );

template<typename L, typename R>
typename append<L const,R>::type oprerator , ( L const &, R & );

template<typename L, typename R>
typename append<L,R const>::type oprerator , ( L &, R const & );

template<typename L, typename R>
typename append<L const,R const>::type oprerator , ( L const &, R
const & );

}

struct array {
result_type operator [] ( Tuple const & );
} a;

Now you can white
a [ _1, 10, _1 ]
which equivalent to
a [ tuple<arg, const int, const arg> (_1, 10, arg () ) ]

Note that you save const qualifiers of original arguments. In this case
it's not important, but sometimes you will need it.
It addition it's possible to build list of n-args without n overloads.

How can you archive it with operator ()?

---
[ 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 ]
Back to top
Alf P. Steinbach
Guest





PostPosted: Thu Oct 26, 2006 10:38 pm    Post subject: Re: Comma within square brackets - not found in Google Code Reply with quote

* Ron Natalie:
Quote:
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.

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


Quote:
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.

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
term. For example, <url: http://www.research.att.com/~bs/array34.c>.

Or, for example, the standard's §8.3.4/4, «When several "array of"
specifications are adjacent, a multidimensional array is created; ...".

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


Quote:
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.

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

--
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 ]
Back to top
John Nagle
Guest





PostPosted: Fri Oct 27, 2006 7:43 am    Post subject: Re: Comma within square brackets - not found in Google Code Reply with quote

Me wrote:
Quote:
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 ]
Back to top
Guest






PostPosted: Mon Oct 30, 2006 3:38 pm    Post subject: Re: Comma within square brackets - not found in Google Code Reply with quote

John Nagle wrote:
Quote:
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.

That bit of wierdness is still in use today. boost::lambda borrowed the
syntax (see http://tinyurl.com/zjafx search for "The BLL supports an
alternative syntax for control expressions"). Then there's also
Phoenix-2 (http://tinyurl.com/b25hr). Call it "abuse" or whatever, but
the point is that you can't match the level of expressiveness with any
other syntax. The whole point with DSEL is that we attempt to get as
close as possible to the target syntax.

Regards,
--
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

---
[ 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 ]
Back to top
Pete Forman
Guest





PostPosted: Mon Oct 30, 2006 10:12 pm    Post subject: Re: Comma within square brackets - not found in Google Code Reply with quote

nagle (AT) animats (DOT) com (John Nagle) writes:

Quote:
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 (AT) westerngeco (DOT) 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 ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.