Topic: Why forbid defining local templates in new proposal?


Author: anthony.williamsNOSPAM@anthonyw.cjb.net (Anthony Williams)
Date: Wed, 12 Mar 2003 18:47:08 +0000 (UTC)
Raw View
richard@ex-parrot.com ("Richard Smith") writes:

> "faisal vali" <fvali@eecs.ku.edu> wrote in message
> news:3E68F29E.1525732E@eecs.ku.edu...
> >
> > In the updated proposal by Anthony Williams "Making Local Templates more
> > Useful" to allow local classes to be used to instantiate template
> > entities (i was mislead by the title into thinking that it was allowing
> > defining local templates)

A typo that unfortunately made it into the papers index :-( The real title is
"Making local Types More Useful"

> > (http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf) it is
> > mentioned that:
> >
> > "For consistency with non-local classes, it may be desirable to allow
> > local classes to be templates, or to have member templates, or even to
> > allow specializations of templates for local classes. However, any of
> > these would require a syntax change, and it has been drawn to my
> > attention that there may be implementation problems. Therefore I do not
> > propose such extensions."
>
> Clearly local template classes and their specialisation would require a
> change to the grammar: they are declared using the template-declaration and
> explicit-specialization terms in the grammar.  I don't see how allowing
> member templates of local classes would "require a syntax change".  As far
> as the grammar is concerned, there is no difference between local and
> non-local classes.

It is a "syntax change" in so far as it would allow a grammatical structure (a
template declaration) somewhere where it is currently forbidden (inside the
definition of a local class).

> > So my questions are as follows:
> > - why is the change of syntax such a big deal? (isn't the syntax
> > decomposition/parsing a fairly well automated process?)
>
> It's automated in that I imagine most major compilers use some tool like
> yacc to generate a parser from a grammar.  This does not however mean it is
> easy: the grammar (as a yacc source file) for gcc-3.2.1 is 4027 lines long.
> Furthermore there are many programs that conform to this grammar but that
> are nonsensical.  For example,
>
>   export template< template<class> class T > using typename T<int>::type;
>
> A compiler needs to give an error if someone writes something like this.
>
> > - what are the challenges with implementing local templates that don't
> > exist with non-locals
>
> I'd be interested to know this, too.

In my discussions with John Spicer about a draft of this paper, he expressed
the opinion that this would require considerable implementation effort for
very little gain. I didn't ask him to elaborate.

Anthony
--
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
Remove NOSPAM when replying, for timely response.

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





Author: llewelly.at@xmission.dot.com (LLeweLLyn)
Date: Thu, 13 Mar 2003 16:36:00 +0000 (UTC)
Raw View
richard@ex-parrot.com ("Richard Smith") writes:
[snip]
> > So my questions are as follows:
> > - why is the change of syntax such a big deal? (isn't the syntax
> > decomposition/parsing a fairly well automated process?)
>
> It's automated in that I imagine most major compilers use some tool like
> yacc to generate a parser from a grammar.  This does not however mean it is
> easy: the grammar (as a yacc source file) for gcc-3.2.1 is 4027 lines long.
[snip]

And the maintainers of gcc long ago came to the conclusion that the
    c++ grammar is hostile to LALR parsing in general, and to a
    bison-generated parser in particular. At some point (gcc 3.4, I
    would guess - it didn't make 3.3), gcc will have a new
    hand-written parser. (See gcc.gnu.org, the News/Annoucements pane,
    6th annoucement down.)

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





Author: fvali@eecs.ku.edu (faisal vali)
Date: Mon, 17 Mar 2003 21:27:02 +0000 (UTC)
Raw View

Anthony Williams wrote:
>
> richard@ex-parrot.com ("Richard Smith") writes:
<snip>
> > "faisal vali" <fvali@eecs.ku.edu> wrote in message
> > > - what are the challenges with implementing local templates that don't
> > > exist with non-locals
> >
> > I'd be interested to know this, too.
>
> In my discussions with John Spicer about a draft of this paper, he expressed
> the opinion that this would require considerable implementation effort for
> very little gain. I didn't ask him to elaborate.
>

Well first of all i want to remedy forgetting to thank the author of the
proposal.
So thanks Mr Williams - this is a feature i continute to miss in my C++
programs, and hopefully, thanks to your efforts, i will not continue to
do so in the near future.

As regards the gain - i too am leaning towards John Spicer's opinion
that it would be insubstantial - since no example has leaped out at me -
and after all Mr. Spicer is a (if not 'the') leading authority on
matters template related (so he should know) - but i must confess - i
haven't given it much serious thought.

My concern is that we don't go the same route that we went with local
types - i.e - with programmers realizing that local templates would
prevent a fair amount of redundant code - and that it was a feature that
should have been added in order to simplify or facilitate the writing of
elegant C++ programs.

So if the decision has not yet been made - lets all discuss the matter
on this forum (at least for those of us constrained to miss the ISO
meetings) and convince each other that local templates truly don't offer
any significant gain.

any thoughts?

regards,
-fas

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





Author: fvali@eecs.ku.edu (faisal vali)
Date: Fri, 7 Mar 2003 23:13:58 +0000 (UTC)
Raw View
In the updated proposal by Anthony Williams "Making Local Templates more
Useful" to allow local classes to be used to instantiate template
entities (i was mislead by the title into thinking that it was allowing
defining local templates)
(http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf) it is
mentioned that:

"For consistency with non-local classes, it may be desirable to allow
local classes to be templates, or to have member templates, or even to
allow specializations of templates for local classes. However, any of
these would require a syntax change, and it has been drawn to my
attention that there may be implementation problems. Therefore I do not
propose such extensions."


So my questions are as follows:
 - why is the change of syntax such a big deal? (isn't the syntax
decomposition/parsing a fairly well automated process?)
 - what are the challenges with implementing local templates that don't
exist with non-locals
 - can anyone think of non-contrived use-cases where using local
templates would have a clear impact on either the readability,
maintainability or the repetitiveness of one's code? (I think i have
one, but i'm going to need some time to formulate it and make sure that
it is indeed worthy)

thanks,
Faisal Vali




I would think that at least member templates would be quite a useful
feature to have in local classes so that you could do

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





Author: richard@ex-parrot.com ("Richard Smith")
Date: Mon, 10 Mar 2003 14:32:56 +0000 (UTC)
Raw View
"faisal vali" <fvali@eecs.ku.edu> wrote in message
news:3E68F29E.1525732E@eecs.ku.edu...
>
> In the updated proposal by Anthony Williams "Making Local Templates more
> Useful" to allow local classes to be used to instantiate template
> entities (i was mislead by the title into thinking that it was allowing
> defining local templates)
> (http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf) it is
> mentioned that:
>
> "For consistency with non-local classes, it may be desirable to allow
> local classes to be templates, or to have member templates, or even to
> allow specializations of templates for local classes. However, any of
> these would require a syntax change, and it has been drawn to my
> attention that there may be implementation problems. Therefore I do not
> propose such extensions."

Clearly local template classes and their specialisation would require a
change to the grammar: they are declared using the template-declaration and
explicit-specialization terms in the grammar.  I don't see how allowing
member templates of local classes would "require a syntax change".  As far
as the grammar is concerned, there is no difference between local and
non-local classes.

> So my questions are as follows:
> - why is the change of syntax such a big deal? (isn't the syntax
> decomposition/parsing a fairly well automated process?)

It's automated in that I imagine most major compilers use some tool like
yacc to generate a parser from a grammar.  This does not however mean it is
easy: the grammar (as a yacc source file) for gcc-3.2.1 is 4027 lines long.
Furthermore there are many programs that conform to this grammar but that
are nonsensical.  For example,

  export template< template<class> class T > using typename T<int>::type;

A compiler needs to give an error if someone writes something like this.

> - what are the challenges with implementing local templates that don't
> exist with non-locals

I'd be interested to know this, too.

--
Richard Smith


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