From -1999234826139946995
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,aef96954609d602c
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1993-08-13 06:04:41 PST
Newsgroups: comp.std.c++
Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!newsgate.watson.ibm.com!yktnews.watson.ibm.com!hawnews.watson.ibm.com!jjb
From: jjb@watson.ibm.com (John Barton)
Subject: Re: Template constraints
Sender: news@hawnews.watson.ibm.com (NNTP News Poster)
Message-ID: <CBp6wn.FpH@hawnews.watson.ibm.com>
Date: Fri, 13 Aug 1993 12:33:59 GMT
Disclaimer: This posting represents the poster's views, not necessarily those of IBM.
References: <rfgCB638z.2t3@netcom.com> <1993Aug4.182811.21153@ucc.su.OZ.AU> <rfgCBAw1F.7Hx@netcom.com> <m663quINNhtq@exodus.Eng.Sun.COM> <244rc6$g7i@nic.lth.se>
Nntp-Posting-Host: jjb.watson.ibm.com
Organization: IBM T.J. Watson Research Center
Lines: 64

In article <244rc6$g7i@nic.lth.se>, dag@control.lth.se (Dag Bruck) writes:
|> In <comp.std.c++> chased@rbbb.Eng.Sun.COM (David Chase) writes:
|> >In article <....> rfg@netcom.com (Ronald F. Guilmette) writes:
|> >>Here is a brief example:
|> >>	template <class T { class M; }> void template_function (T);
|> >
|> >Is there any particular reason why you wouldn't extend this to include
|> >more than just type constraints?
|> >
|> >   template <class T { unsigned hash(T);
|> >                        T();
|> >                        ~T();
|> >                        int operator==()(T,T);
|> >                       } > class Htable { .....
|> >   } ;
|> 
|> I think this is absolutely hideous :-)  I really don't want to read
|> template argument lists like that.  However, I think you could do it
|> as a two-step process by first declaring a template-argument-template,
|> if you excuse the pun:
|> 
|>   class T_templ {
|> 	unsigned hash(T);
|>         T();
|>         ~T();
|>         int operator==()(T,T);
|>   };
|> 
|>   template <class T : T_templ > class Htable { .....
|>   } ;
|> 
|> So the idea is that you specify the minimum interface in a separate
|> class declaration, and then only list the class name(s) in the
|> template argument list.  There are two main advantages:
|> 
|> 	- the template argument lists is kept reasonably short
|> 
|> 	- it is easy to see that a group of template classes or
|> 	  template functions have the same constraints, because
|> 	  the all refer to the same name.  It is also easier to
|> 	  tell if two type arguments have the same constraints.
|> 
|> Anyone cares to comment?
|> 
|> 
|> 			-- Dag

  Any compiler or C++ syntax analyzer can produce the information
listed in T_templ above.  Having the programmer type it in is silly.
On the other hand, an analyzer cannot determine what "T::X * y;" means
by any analysis short of template instantiation or guessing.  We need
a way to forward declare the types for template arguments.  We have
exactly the same problem for nested types in general: we cannot
now forward declare a type nested inside of another type.
  There is a sensible line we can draw for limiting the
pre-declaration info to a template parameter: limit it to types
relations essential for syntax analysis.  Accomplish this and
then work on wider issues.
  
-- 
John.

John J. Barton        jjb@watson.ibm.com            (914)784-6645
H1-C13 IBM Watson Research Center P.O. Box 704 Hawthorne NY 10598


