From 722278997109653872
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ede379f5dbbc1549
X-Google-Attributes: gidf78e5,public
From: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Subject: Re: Suggestion: "typeof" keyword
Date: 1999/08/14
Message-ID: <37B46035.CFD0324E@physik.tu-muenchen.de>#1/1
X-Deja-AN: 512556929
Content-Transfer-Encoding: 7bit
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <7nt3vl$1oe$1@nnrp1.deja.com> <7oh7o8$t3f$1@nnrp1.deja.com> <37AE541B.A998F729@cs.utu.fi> <cTqioZABDwr3EwfO@robinton.demon.co.uk> <37AFAC37.6B7F4253@cs.utu.fi> <7opt86$pku$1@nnrp1.deja.com>
X-Original-Date: Fri, 13 Aug 1999 20:13:09 +0200
X-Accept-Language: German/Germany, de-DE, German, de, en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 934619026 32509 128.250.29.17 (14 Aug 1999 08:23:46 GMT)
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN7Und+EDnX0m9pzZAQFIGwF6A3cbhSxSLS7f73qoRLg/oRWIahcrAE8V 7OF+l4Wp8TFI/DW9mqjTA63rQW0ruzSN =rXad
Mime-Version: 1.0
NNTP-Posting-Date: 14 Aug 1999 08:23:46 GMT
Newsgroups: comp.std.c++

sirwillard@my-deja.com wrote:
> 
> In article <37AFAC37.6B7F4253@cs.utu.fi>,
>   Jaakko =?iso-8859-1?Q?J=E4rvi?= <jaakko.jarvi@cs.utu.fi> wrote:
> > Francis Glassborow wrote:
> > >
> > > with typeof you do not need declare, however declare would not
> provide
> > > all the utility of typeof, and is less clear in intent.
> >
> > I agree, that declare would not provide all the utility of typeof,
> > but I still think it would be useful (in addition to typeof).
> >
> > See my example:
> > > typeof(a*b+c*d+e/f) x = a*b+c*d+e/f;
> > vs.
> > > declare x = a*b+c*d+e/f;
> > I find the first line less clear in intent.
> 
> I don't.  Even if I agreed, however, I think the idiom to be poor.
> What you are doing is asking the compiler to determine the type of a
> complex expression and at the same time declare an instance of that
> type.  If I can't determine the type at the time I write such a line,
> I'd hardly want the compiler to do so for me.  There may be rare cases
> in which this is useful, but they are too rare to warrant yet another
> keyword when the typeof keyword gives the same identical functionality.

Think f.ex. of expression templates. There you can have
something like

void foo()
{
  Placeholder x;
  integrate(sin(x)/x, 1, 3);
}

Here sin(x)/x evaluates to a type like

Expression<Quotient<Sinus<Placeholder> >, Placeholder>

and integrate is a template on its first parameter.

Now, assume you want to compare the quality of two integration
routines on a complex expression, say sin(x)/x + tan(x)*exp(-3*x*x)

Now what is more clear (and less error prone):

double testinteg()
{
  Placeholder x;
  Expression<Sum<Quotient<Sinus<Placeholder>,Placeholder>,
                 Product<Tan<Placeholder>,
                         Exp<Times<Times<Constant<-3>,x>,x> > > > >
    expr = sin(x)/x + tan(x)*exp(-3*x*x);

  double result1 = integrate1(expr, 1, 3);
  double result2 = integrate2(expr, 1, 3);
  return (result1-result2)/result2;
}

or

double testinteg()
{
  Placeholder x;
  typeof(sin(x)/x + tan(x)*exp(-3*x*x))
    expr = sin(x)/x + tan(x)*exp(-3*x*x);
  // ...
}

or even

double testinteg()
{
  Placeholder x;
  declare expr = sin(x)/x + tan(x)*exp(-3*x*x);
  // ...
}

I guess if making more use of templates, more of those
situations would arise.

[...]
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



