From -8592565204141265749
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ede379f5dbbc1549
X-Google-Attributes: gidf78e5,public
From: niklasb@my-deja.com
Subject: Re: Suggestion: "typeof" keyword
Date: 1999/08/23
Message-ID: <7pk6r6$689$1@nnrp1.deja.com>#1/1
X-Deja-AN: 516089513
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> <t7r9laz5hj.fsf@calumny.jyacc.com> <7oup0a$8g2$1@nnrp1.deja.com> <37B3C2AD.5AB722AE@lucent.com> <37B5A571.449B@wanadoo.fr> <37B908A8.717CAC2C@lucent.com> <CVJFZFAbaWu3Ew15@robinton.demon.co.uk> <7pcvjs$tk4$1@nnrp1.deja.com> <user-1808991258230001@aus-as3-121.io.com> <7phk8n$b26$1@nnrp1.deja.com> <37BD2185.C0047293@physik.tu-muenchen.de>
X-Original-Date: Fri, 20 Aug 1999 18:30:16 GMT
X-Authentication-Warning: backdraft.briar.org: smap set sender to <news@dejanews.com> using -f
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)
X-Complaints-To: news@news.unimelb.edu.au
X-Http-Proxy: 1.0 RED-PRXY-07, 1.0 x43.deja.com:80 (Squid/1.1.22) for client 131.107.3.77
X-Trace: izvestia.its.unimelb.edu.au 935398001 27299 128.250.29.17 (23 Aug 1999 08:46:40 GMT)
Organization: Deja.com - Share what you know. Learn what you don't.
X-Article-Creation-Date: Fri Aug 20 18:30:16 1999 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN8EKUeEDnX0m9pzZAQEoIgF6AgNV1SWFAD3e3J5UQnrhSpO8bB4R1bvo JS2wG9r1lW9FEb5jpnHB+QvLiRpM2bYg =hW59
X-MyDeja-Info: XMYDJUIDniklasb
NNTP-Posting-Date: 23 Aug 1999 08:46:40 GMT
Newsgroups: comp.std.c++

In article <37BD2185.C0047293@physik.tu-muenchen.de>,
  Christopher Eltschka <celtschk@physik.tu-muenchen.de> wrote:
>
> [ snip ]
>
> I think top level const should be preserved (but I agree that
> reference should be removed).
>
> [ snip ]
>
> And my expectation would be that the following should
> always work:
>
> any_type foo;
> typeof(foo)* bar = &foo;
>
> And now assume any_type is int const.

You've convinced me. The reference should be stripped,
but the CV qualifier should be retained. Just to give
something concrete to talk about, let me try once again
to suggest a set of rules:

1 The typeof operator yields the type of its operand.
  The operand is an expression, which is not evaluated.
  The result is the CV-qualified type of the expression
  (the static type, not the dynamic type of the object
  returned by the expression).

  <Example>
  void func();
  typeof(func)* fp = func;
  </Example>

2 The typeof operator never yields a reference type.
  When applied to a reference, the result is the
  referenced type.

  <Example>
  vector<int> v(1);
  typeof(v[0]) x = v[0];  // int x = v[0];
  typeof(v[0])& y = v[0]; // int& y = v[0];
  </Example>

3 Within the context of a typeof expression, a temporary
  object of any type T can be instantiated using

   - initialization notation, T(), whether or not
     T has a default constructor, or

   - cast notation, (T)expr, whether or not a
     conversion from typeof(expr) to T exists.

  (Because the expression is not evaluated, it does
  not matter whether the temporary object can be
  initialized correctly.)

4 In a variable declaration, the typeof operand can
  be "...", representing the expression used to
  initialize the variable.

  <Example>
  typeof(...) i = v.begin();
  typeof(...) j( v.end() );
  </Example>

Summary of changes:
 - eliminated typeof(type-id), as it does nothing [1]
 - result is now the CV-qualified type [1,2]
 - added the rule about allowing arbitrary casts [3]
 - added typeof(...), similar to proposed declare [4]


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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              ]



