From 8429512908701648883
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: <37B13085.5CB17541@physik.tu-muenchen.de>#1/1
X-Deja-AN: 512778791
Content-Transfer-Encoding: 7bit
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
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>
X-Original-Date: Wed, 11 Aug 1999 10:12:53 +0200
X-Accept-Language: German/Germany, de-DE, German, de, en
Content-Type: text/plain; charset=us-ascii
Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany)
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUAN7WkiqwEuYhIxRhxAQFPKAH/RtZJv+uhbwpd05PE6EfCINbbi4Z9wuzL jfXvmA3umPIlvCSQgy/4Xoc3wgo4+El7zqUE21b31pAsmP2cTUAAjw== =xun6
Mime-Version: 1.0
Newsgroups: comp.std.c++

Hyman Rosen wrote:
> 
> Francis Glassborow <francis@robinton.demon.co.uk> writes:
> > Likewise, if you can convince me that it is worthwhile, together with
> > the kind of material Dietmar suggested I would try to persuade the UK
> > C++ Panel (equivalent of J16) to support it.  But you must put in the
> > work so that people like myself and Dietmar can argue for it.
> 
> This is not anything like a formal proposal, but perhaps it's a
> starting point.
> 
> Given
> 
> namespace std
> {
>         template<typename T> void __typeof__(volatile const T &);
> }
> 
> I propose that the type of 'typeof(expr)' be defined to be the same
> as the deduced type of T in the call 'std::__typeof__(expr);'. The
> expression 'expr' is not evaluated.
> 
> This semantics makes typeof of a reference be the same as typeof of
> its referrant, and discards top-level const and volatile, somewhat
> like the behavior of sizeof.

I'd prefer it to be the deduced type of

template<class T> void foo(T&)

i.e. it still contains the top level const/volatile, but discards
references.

It's not what g++ uses, but I've got surprised by g++ when
the following code wasn't OK:

int main()
{
  int const i;
  typeof(i)* pi = &i; // initialisation of int* with int const*!
}

Also note that if typeof gives the full cv qualified type, you
can still get the unqualified type with the following declarations:

template<class T> T discard_const(T const&);
template<class T> T discard_volatile(T volatile&);
template<class T> T discard_cv(T const volatile&);

typeof(discard_cv(expr)) foo;
  // the same type as your typeof definition would result in

OTOH, I don't see a way how to re-create the const conce it was
discarded.

One could argue that the same should be true for references;
however, since references always act like the referenced object
(except on initialisation), it IMHO should do so with typeof as
well.
---
[ 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              ]



