473,387 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

why c++ not support typeof()?

Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int()£»
Typeof(a) b = new Typeof(a)()£»
Q2£º

NOT about c++:

How to read older post? for sample some one write on year 2002?
I tried google , no lucky.

thank you .

your key9
Mar 20 '06 #1
15 29300
Not like java, Anyone CAN NOT not know the realy type to be related an
object at the run time.
Think "void", "type casting", etc.

"void" can receive all of type.
"type casting" can many different type.

Mar 20 '06 #2
Key9 wrote:
Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int()£»
Typeof(a) b = new Typeof(a)()£»
Because C++ is statically typed.

You can produce similar effects at runtime with the "virtual
constructor" or factory method idioms.

You can produce similar effects which are statically bound, by using
templates.

Q2£º

NOT about c++:
Well then lets make it about C++.
How to read older post? for sample some one write on year 2002?
I tried google , no lucky.


You mean, how do you read archived posts of comp.lang.c++?

http://groups.google.com/group/comp.lang.c++

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 20 '06 #3
Key9 wrote:
Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int();
Typeof(a) b = new Typeof(a)();


There was no proposal for this in 1998 when C++98 was introduced. It
may appear
in the next version, although probably by another name. (decltype,
IIRC, because
it's the *declared* type of 'a' that determines decltype(a))

Of course, an STL implementation make take advantage of the
implementation
and use __typeof today, if the compiler has it.

HTH,
Michiel Salters

Mar 20 '06 #4
* Mi*************@tomtom.com:
Key9 wrote:
Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int();
Typeof(a) b = new Typeof(a)();


There was no proposal for this in 1998 when C++98 was introduced. It
may appear
in the next version, although probably by another name. (decltype,
IIRC, because
it's the *declared* type of 'a' that determines decltype(a))


Of course you may not know, but, if you do know, or someone, whose
brilliant idea was it to /yet again/ disregard existing practice?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 20 '06 #5
Key9 wrote:
Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int()£»
Typeof(a) b = new Typeof(a)()£»


The next version of the boost distro:
http://www.boost.org
will support a typeof macro which will achieve this functionality with
some technicalities.

regards
Andy Little

Mar 20 '06 #6
Ben Pope wrote:
//pesudo code
int a = new int()£»
Typeof(a) b = new Typeof(a)()£»


Because C++ is statically typed.


I thought Boost supported a huge inhumane cracker that does that.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Mar 20 '06 #7
andy wrote:
The next version of the boost distro:
http://www.boost.org
will support a typeof macro which will achieve this functionality with
some technicalities.


Is it in foreach.zip, here?

http://www.boost-consulting.com/vaul...ory=Algorithms

I would figure out for myself, but I can't seem to download the file.

(This is obviously my fault - not Boosts!!)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Mar 20 '06 #8
REH

Alf P. Steinbach wrote:
* Mi*************@tomtom.com:
Key9 wrote:
Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int();
Typeof(a) b = new Typeof(a)();


There was no proposal for this in 1998 when C++98 was introduced. It
may appear
in the next version, although probably by another name. (decltype,
IIRC, because
it's the *declared* type of 'a' that determines decltype(a))


Of course you may not know, but, if you do know, or someone, whose
brilliant idea was it to /yet again/ disregard existing practice?


I seem to recall an explanation was given for using decltype over
typeof, but I cannot find it. The reason is not mentioned in N1705.

REH

Mar 20 '06 #9

"Phlip" wrote:
The next version of the boost distro:
http://www.boost.org
will support a typeof macro which will achieve this functionality with
some technicalities.


Is it in foreach.zip, here?

http://www.boost-consulting.com/vaul...ory=Algorithms

I would figure out for myself, but I can't seem to download the file.

No, it is not in foreach, it is different library.

You may download the fresh CVS or wait couple
of weeks for Boost 1.34 where it'l be released.

The library uses native typeof where available
(gcc) and emulation elsewhere.
The compile times for emulated typeof may be high.

/Pavel

Mar 20 '06 #10
Pavel Vozenilek wrote:
You may download the fresh CVS or wait couple
of weeks for Boost 1.34 where it'l be released.

The library uses native typeof where available
(gcc) and emulation elsewhere.
The compile times for emulated typeof may be high.


Even for emulated typeof the compile times are not greatly problematic
as, AFAIK, a lot of effort has been spent on this area. The main
hurdle, which is required for portability, is the need to register a
type( and maybe associated types) with the typeof mechanism. Of course
registration can be a No-op, in native mode, on those platforms that
also support the 'native' mode.

regards
Andy Little

Mar 21 '06 #11
REH wrote:
I seem to recall an explanation was given for using decltype over
typeof, but I cannot find it. The reason is not mentioned in N1705.


I think decltype preserves references, whereas typeof doesnt:

std::ostream& my_output();

decl_type(my_output()) t1;
typeof(my_output()) t2;

t1 is std::ostream&
t2 is std::ostream.

I think <---!!!

regards
Andy Little

Mar 21 '06 #12
Alf P. Steinbach wrote:
* Mi*************@tomtom.com:
It (typeof) may appear in the next version, although probably by
another name. (decltype,
IIRC, because
it's the *declared* type of 'a' that determines decltype(a))


Of course you may not know, but, if you do know, or someone, whose
brilliant idea was it to /yet again/ disregard existing practice?


What existing practice? The name part? Or the behavior? When the EWG
looked
at the existing practice, it was discovered that there are really two
things that
they try to achieve. Because of this, existing practice was
inconsistent. The
EWG liked both, but decided that you can't have both things and a
single name.
AFAIK, the idea is still to have

auto x = expr; // where the type of x is "what you expect" and
decltype(expr) // where decltype(x) is really the type from the
declaration.

to cover the two common typeof cases. Existing practice is pretty much
anything in between.

HTH,
Michiel Salters

Mar 21 '06 #13
* Mi*************@tomtom.com:
Alf P. Steinbach wrote:
* Mi*************@tomtom.com:
It (typeof) may appear in the next version, although probably by
another name. (decltype,
IIRC, because
it's the *declared* type of 'a' that determines decltype(a)) Of course you may not know, but, if you do know, or someone, whose
brilliant idea was it to /yet again/ disregard existing practice?


What existing practice? The name part?


The name part, since AFAIK there's no room for deviant behavior... ;-)

Or the behavior? When the EWG
looked
at the existing practice, it was discovered that there are really two
things that
they try to achieve. Because of this, existing practice was
inconsistent. The
EWG liked both, but decided that you can't have both things and a
single name.
AFAIK, the idea is still to have

auto x = expr; // where the type of x is "what you expect" and
decltype(expr) // where decltype(x) is really the type from the
declaration.

to cover the two common typeof cases. Existing practice is pretty much
anything in between.


Is it?

When I typed "gnu typeof" into the Firefox address line, I endeth up at
<url:
http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/gcc/Typeof.html>.

I'm unaware of any existing practice that gives x above, in your
example, the /dynamic/ type of expr, or anything but the static type.

So this second thing you're referring to, I don't see it: what is it?

As I see it, there must be some COBOL saboteur on the committee...
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 21 '06 #14
REH

an**@servocomm.freeserve.co.uk wrote:
REH wrote:
I seem to recall an explanation was given for using decltype over
typeof, but I cannot find it. The reason is not mentioned in N1705.


I think decltype preserves references, whereas typeof doesnt:

std::ostream& my_output();

decl_type(my_output()) t1;
typeof(my_output()) t2;

t1 is std::ostream&
t2 is std::ostream.

I think <---!!!

regards
Andy Little


Well, since there is no standard definition of typeof, who's to say.
GCC's version does not. decltype not only preserves references, if
given an lvalue it "returns" a reference type.

REH

Mar 21 '06 #15
Key9 wrote:
On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?


Indeed, why not have an operator which extracts type information from
an expression which can be used in a cast or declaration?

Because it would be way too easy to implement, and way too useful.

That is not the C and C++ way.

Mar 21 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul Reed | last post by:
Hello, I have a function that runs at load time and throws a an "Object Doesn't Support This Propertiy or Method" jscript error. The offending line is "if (type != "undefined") ". If I change...
4
by: Eric | last post by:
I need to do the following but it doesn't compile if(typeof(listBox1.Items) == typeof(string)){ return; } typeof(listBox1.Items) doesn't work at all. My listBox has 2 types of items in...
9
by: James Geurts | last post by:
Hey all... I posted this in the vs.net ide group too, but people are not answering, so I figured that it might be more appropriate here. I'm not sure if I'm adding a designer to my code properly. ...
11
by: Jason Kendall | last post by:
Why doesn't the new "IsNot" operator work in conjunction with 'Typeof'?
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
0
by: onyxring | last post by:
I'm reposting this, because I had a bit of difficulty last time and think that it might have fallen through the cracks. If I'm posting to the wrong groups, please let me know. Surely someone has...
20
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues =...
15
by: RobG | last post by:
When using createEvent, an eventType parameter must be provided as an argument. This can be one of those specified in DOM 2 or 3 Events, or it might be a proprietary eventType. My problem is...
2
by: bips2008 | last post by:
The code seems to work fine in other browser but in IE it throws this error. This is very urgent for me and any help would be greatly appreciated For your convienence i have posted the code for the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.