From -2205288806145966020
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ede379f5dbbc1549,start
X-Google-Attributes: gidf78e5,public
From: niklasb@my-deja.com
Subject: Suggestion: "typeof" keyword
Date: 1999/08/04
Message-ID: <7nt3vl$1oe$1@nnrp1.deja.com>#1/1
X-Deja-AN: 508720306
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
X-Original-Date: Fri, 30 Jul 1999 21:03:55 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-Http-Proxy: 1.0 RED-PRXY-01, 1.0 x38.deja.com:80 (Squid/1.1.22) for client 131.107.3.71
Organization: Deja.com - Share what you know. Learn what you don't.
X-Article-Creation-Date: Fri Jul 30 21:03:55 1999 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUAN6gRSqwEuYhIxRhxAQHfgwIAj6TyJGB1pFhBhNOhN5jOIkv5jnw24iHh RaLSKXvlY9u0jTiMsdmYyNTUCwlrLDjX7alaXdQRXjw7sRROyk9IQA== =jhfx
X-MyDeja-Info: XMYDJUIDniklasb
Newsgroups: comp.std.c++

Suppose I'm writing a template function and II is an unknown
iterator type. How can I refer to the type one gets by
dereferencing an II object?

In many cases I could say II::value_type, but only if II is
a class that contains a typedef for value_type. What if II is
a simple pointer type? The use of the "typedef ... value_type"
convention in the standard library only highlights the need
for a more universal mechanism.

I have in mind a keyword, typeof, which would yield the type
of an expression. Like its cousin "sizeof," typeof would not
actually evaluate anything at run-time.

Does anyone else think such a keyword would be valuable? Or
is this a solution in search of a problem? Following is a
(somewhat contrived) example of how typeof might be used.


template<class II>
II FindEndQuote(II isz)
{
    typedef typeof(*isz) Ch;
    Ch quote = *isz;
    do {
        ++isz;
    } while (*isz != quote && *isz != Ch(0));
    return isz;
}

char* Foo(char* psz)
{
    return FindEndQuote(psz);
}


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              ]



