From 5457381986354470794
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: <37B45C97.604C69D0@physik.tu-muenchen.de>#1/1
X-Deja-AN: 512556928
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> <7ol6hi$ej9$2@news.BelWue.DE> <cTiioXAhAwr3Ew$X@robinton.demon.co.uk> <t7d7ww1vrz.fsf@calumny.jyacc.com> <e4DSyfA4ALs3Ew0Q@robinton.demon.co.uk> <t7hfm6ytow.fsf@calumny.jyacc.com> <120819991357412479%lisa_lippincott@advisories.com>
X-Original-Date: Fri, 13 Aug 1999 19:57:43 +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 934618981 32249 128.250.29.17 (14 Aug 1999 08:23:01 GMT)
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN7UnT+EDnX0m9pzZAQHZcAF/ZhhBWwoFrJPHmSuRbT3E4+MnyPEh/ZMX 5HDuSSCu0Z8HF4QwukHCixyxy8n0lItU =SY33
Mime-Version: 1.0
NNTP-Posting-Date: 14 Aug 1999 08:23:01 GMT
Newsgroups: comp.std.c++

Lisa Lippincott wrote:
> 
> Here's an awkward fact about the typeof proposal: it seems useful within
> a function, where there are lots of variables to make expressions from.
> But it seems more difficult to use in a class definition or in
> a function declaration, because there's no handy syntax for an
> anonymous object of a given type.  Consider:
> 
> template < class A, class B, class C >
> /* what type goes here? */
> MultiplyAdd( const A& a, const B& b, const C& c )
>   { return a * b + c; }
> 
> Someone has already posted an example like this where the result type
> is "typeof( A() * B() + C() )," but that requires the default constructors
> of the types to be declared (implicitly or not) and accessible.  The best
> solution I've come up with which doesn't have such a restriction is
> 
>    typeof( *(A*)(0) * *(B*)(0) + *(C*)(0) )
> 
> which seems less than elegant.

You could make a declaration

template<class T> T obj();

Then you could write it as

template<class A, class B, class C>
 typeof(obj<A>() * obj<B>() + obj<C>())
  MultiplyAdd(A const& a, B const& b, C const& c)
{
  return a*b+c;
}

Of course, if one invents a syntax for "an unnamed lvalue
of type T", only usable in typeof, then you could do a nicer
syntax:

template<class A, class B, class C>
 typeof([A]*[B]+[C]) MultiplyAdd(A const& a, B const& b, C const& c)
{
  return a*b+c;
}

However, I prefer being able to do something in an awkward syntax
to not being able to do it at all.
---
[ 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              ]



