 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Samee Zahur Guest
|
Posted: Fri May 13, 2005 6:04 am Post subject: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of ending
two template paramenter lists in a row? That would make things like
vector<vector legal without any extra space!
I know it is sometimes good coding practice to keep the space, but
shouldn't coding style be there for the programmer to decide? What is
the rationale behind this language design?
Samee
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Llewelly Guest
|
Posted: Fri May 13, 2005 1:08 pm Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
"Samee Zahur" <samee.zahur (AT) gmail (DOT) com> writes:
| Quote: | We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of ending
two template paramenter lists in a row? That would make things like
vector<vector legal without any extra space!
[snip] |
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
David Abrahams Guest
|
Posted: Fri May 13, 2005 1:42 pm Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
"Samee Zahur" <samee.zahur (AT) gmail (DOT) com> writes:
| Quote: | We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of ending
two template paramenter lists in a row? That would make things like
vector<vector legal without any extra space!
I know it is sometimes good coding practice to keep the space, but
shouldn't coding style be there for the programmer to decide? What is
the rationale behind this language design?
|
No particular rationale; it's being fixed for the next version of the
C++ standard.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Pete Becker Guest
|
Posted: Fri May 13, 2005 2:24 pm Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
David Abrahams wrote:
| Quote: |
No particular rationale; it's being fixed for the next version of the
C++ standard.
|
One very good rationale: it's a fundamental change to the maximum munch
rule that C and C++ lexing is explicitly based on. Which is why making
this change requires careful analysis, as in the paper cited in another
reply.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
John Nagle Guest
|
Posted: Sat May 14, 2005 2:44 am Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
Llewelly wrote:
| Quote: | "Samee Zahur" <samee.zahur (AT) gmail (DOT) com> writes:
We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of ending
two template paramenter lists in a row? That would make things like
vector<vector legal without any extra space!
[snip]
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html
|
That breaks existing code, silently. The committee usually
rejects such suggestions.
John Nagle
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Jerry Coffin Guest
|
Posted: Sat May 14, 2005 3:45 am Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
Samee Zahur wrote:
| Quote: | We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of
ending two template paramenter lists in a row? That would make
things like vector<vector legal without any extra space!
I know it is sometimes good coding practice to keep the space, but
shouldn't coding style be there for the programmer to decide? What is
the rationale behind this language design?
|
I don't believe there's a way of changing this without breaking or
changing the meaning of at least some existing, legitimate code. This
seems to be widely enough seen as a problem that it'll probably change,
but when it does it will probably break or change the meaning of
something else. It does seem likely that the "Something else" in
question is obscure, while this is common, so the tradeoff may be
reasonable, but it should at least be clear to those involved that it
really is a tradeoff, not a simple situation of fixing something that
has no side-effects.
--
Later,
Jerry.
The universe is a figment of its own imagination.
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Samee Zahur Guest
|
Posted: Sun May 15, 2005 4:30 pm Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
Thanks everyone for the replies and references. I read through n1757,
but how far has it gone into actually being accepted? I feel the
proposal there is fine, since I really doubt if there really is any
existing code out in the real world that actually will break down.
(except for tutorial codes meaning to show a possible source of
programmer's confusion)
For everyone's scrutiny, let me give another alternative here which
will not break any existing code - parse it as it does now, and try to
accept >> as a double angle bracket only if treating it like a
right-shift op raises a syntax error.I believe that this approach will
make it easier for compiler vendors to implement this (since all
existing rules stay as-is), although I will admit that I've never been
involved in any compiler writing before. Downsides I can think of:
- humans may find it harder to figure out the real meaning of a '>>'
token in certain contexts.
- in case of multiple instances of '>>' in the same line, there can be
more than one valid interpretation. In these particularly rare cases,
the statement can be flagged an error due to ambiguity forcing the
programmer to resort back to inserting a space wherever needed. Or,
there can be priority rules which decide which one gets interpreted as
what (but this can in turn lead to silent bugs since the compiler reads
something the programmer didn't mean - not a good approach).
Any opinions on this?
Samee
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Ron House Guest
|
Posted: Mon May 16, 2005 4:20 pm Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
Samee Zahur wrote:
| Quote: | We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of ending
two template paramenter lists in a row? That would make things like
vector<vector legal without any extra space!
I know it is sometimes good coding practice to keep the space, but
shouldn't coding style be there for the programmer to decide? What is
the rationale behind this language design?
|
I can think of one reason: it complicates the parser no end. A recursive
algorithm looking for a type is primed to find vector<something>, and
that something is recursively any type, and so might be vector<int>. But
to detect that >> ends two different recursive levels involves a big
redesign of such a parser - and for no real benefit; bung in the space
and it's fixed.
--
Ron House [email]house (AT) usq (DOT) edu.au[/email]
http://www.sci.usq.edu.au/staff/house
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Mon May 16, 2005 4:21 pm Post subject: Re: Why has vector<vector<int>> been *kept* illegal? |
|
|
"Samee Zahur" <samee.zahur (AT) gmail (DOT) com> wrote
| Quote: | We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of ending
two template paramenter lists in a row? That would make things like
vector<vector legal without any extra space!
I know it is sometimes good coding practice to keep the space, but
shouldn't coding style be there for the programmer to decide? What is
the rationale behind this language design?
|
The rationale stems from a basic principle of C++ (and C) parsing
known as the "maximum munch" rule. It says that the longest
sequence of characters that can make a valid token is always
the next token. Thus ">>" always wins out over ">" ">".
Having said that, I must report that the C++ committee seems to
have solved this annoying problem last month in Lillehammer. The
next revision of C++ will indeed accept "vector<vector"
with the meaning we all want.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
James Dennett Guest
|
Posted: Mon May 16, 2005 4:22 pm Post subject: Re: Q: Why has vector<vector<int>> been *kept* illegal? |
|
|
John Nagle wrote:
| Quote: |
Llewelly wrote:
"Samee Zahur" <samee.zahur (AT) gmail (DOT) com> writes:
We know that > can be a 'greater-than' operator, or it can be an
ending-delimiter for template parameters.
So why has the >> operator not been defined as being capable of ending
two template paramenter lists in a row? That would make things like
vector<vector legal without any extra space!
[snip]
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html
That breaks existing code, silently. The committee usually
rejects such suggestions.
John Nagle
|
True, however this particular case seems to have significant
support because of the perceived cost of sticking with the
status quo, and the apparent scarcity of code which would
be broken by the change.
-- James
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
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
|
|