OT: strange c++ cast [Was: Named parameters]

N

Nick Keighley

Frederick said:
jaysome posted:

[testing an unsigned against -1]
If I was writing C++ code, I'd have the choice of:

numeric_limits< Type >::max()

But nonetheless I'd still use -1.

As for the warning sending chills up your spine, you can always cast it
away:

i != (unsigned)-1;

or, in C++:

i != implicit_cast<unsigned>( -1 );

is this a new type of cast?


--
Nick Keighley

"Using a 64-bit value introduces a new wrap around date in about 290
billion
years, on Sunday, December 4, 292,277,026,596 15:30:08 UTC. This
problem is
not, however, widely regarded as a pressing issue."
wiki/Year_2038_problem
 
V

Victor Bazarov

Nick said:
Frederick said:
jaysome posted:

[testing an unsigned against -1]
If I was writing C++ code, I'd have the choice of:

numeric_limits< Type >::max()

But nonetheless I'd still use -1.

As for the warning sending chills up your spine, you can always cast
it away:

i != (unsigned)-1;

or, in C++:

i != implicit_cast<unsigned>( -1 );

is this a new type of cast?

I think it exists in Boost.

Also, it's something that was recently under discussion in comp.std.c++.
Check out the thread "Defect: Missing fundamental feature!"

http://groups.google.com/group/comp.std.c++/browse_frm/thread/8b7617618a67f610/

V
 
V

Victor Bazarov

Nick Keighley wrote:

[Please don't cross-post C++ questions to comp.lang.c, it gets them mad]
Frederick said:
jaysome posted:

[testing an unsigned against -1]
If I was writing C++ code, I'd have the choice of:

numeric_limits< Type >::max()

But nonetheless I'd still use -1.

As for the warning sending chills up your spine, you can always cast
it away:

i != (unsigned)-1;

or, in C++:

i != implicit_cast<unsigned>( -1 );

is this a new type of cast?

I think it exists in Boost.

Also, it's something that was recently under discussion in comp.std.c++.
Check out the thread "Defect: Missing fundamental feature!"

http://groups.google.com/group/comp.std.c++/browse_frm/thread/8b7617618a67f610/

V
 
N

Nick Keighley

[Please don't cross-post C++ questions to comp.lang.c, it gets them mad]

I wouldn't normally, but the post I was replying to included C++ code
on
comp.lang.c. If it was wrong then I thought it should be pointed out on
clc.
Though of course anyone one who takes C++ advice from comp.lang.c is in

a state of sin...

[testing an unsigned against -1]
Warning 650: Constant '-1' out of range for operator '!='

If I was writing C++ code, I'd have the choice of:

numeric_limits< Type >::max()

But nonetheless I'd still use -1.

As for the warning sending chills up your spine, you can always cast
it away:

i != (unsigned)-1;

or, in C++:

i != implicit_cast<unsigned>( -1 );

is this a new type of cast?

I think it exists in Boost.

Also, it's something that was recently under discussion in comp.std.c++.
Check out the thread "Defect: Missing fundamental feature!"

http://groups.google.com/group/comp.std.c++/browse_frm/thread/8b7617618a67f610/

ah. Interesting. Thankyou very much


--
Nick Keighley

"If, indeed the subatomic energy in the stars is being freely
used to maintain their great furnaces, it seems to bring a little
nearer to fulfillment our dreams of controlling this latent
power for the well-being of the human race - or for its suicide."
Aurthur S. Eddington "The Internal Constitution of the Stars" 1926
 
F

Frederick Gotham

Nick Keighley posted:

is this a new type of cast?


Yes, I realise we're off-topic here, but the three new-style casts are:

static_cast
reinterpret_cast
const_cast


Many people, (myself included), have wanted a fourth one, "implicit_cast".
Until it gets officially added to the language, we can achieve its
functionality using a template provided by Boost.
 
P

Phlip

[followups set to C++]

Many people, (myself included), have wanted a fourth one, "implicit_cast".
Until it gets officially added to the language, we can achieve its
functionality using a template provided by Boost.

Why should it be a keyword? Or do you just mean someone should move the
template from Boost to the Standard? What would a keyword do that the
template couldn't?

I like languages that permit us to build as many of its keyword-level things
from primitives as possible...
 
M

Marcus Kwok

In comp.lang.c++ Frederick Gotham said:
Nick Keighley posted:

Yes, I realise we're off-topic here, but the three new-style casts are:

static_cast
reinterpret_cast
const_cast

You forgot dynamic_cast.

Followups set to clc++ only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top